Is there a limit to the number of View Controllers for an app?

Hello all.


In another post, the issue of the number of view controllers for an iPad app came up. Is there a limit? For reasons I won't go into due to the length of time to explain, my app has many view controllers. Plus, if you tell me there is a limit, could you supply your info source for me?


Thank you in advance.


JR

Classes (and thus view controllers) are loaded by name. Thus any limits that you encounter are going to be accidental byproducts of the various file formats involved. But at a certain, arbitrary, point, your application is simply going to fail to load because the amount of time required to verify the signature on your binary is going to exceed limit allowed by the application launch watchdog.


So, on the one hand, no, there is no limit to the number of view controllers you can have in your project. On the other hand, after a few thousand (or tens of thousands) classes you're likely to end up producing a binary that won't actually run any more.

Hello NotMyName


Well, if I'm understanding you correctly, I have nothing to worry about. In my app, the number of View Controllers coupled with their corresponding View Controller classes equal the number of pages in my comic book and when that is finished it will between 70 to a 100 pages.


What a relief! For a while I was getting the creeps.


JR

But if you're doing a book style app, you shouldn't have a view controller for every page, that's the equivalent to driving a different car to work every day.


A better way to handle that is to have a view inside one view controller that renders the text (or image) of each page when the user requests it. You could have maybe three of these views inside of a scroll view and swap them out as the user moves left and right.


Your code should be as generic as possible to be able to handle all situations. Like say you decide to add 10 more pages to your comic book. That shouldn't take any time at all as you only have to import the content into the app and the app would already know how to display any number of pages.

As an example, take a look at the PageControl sample project. It shows roughly what I'm talking about and only uses 3 views to scroll any number of pages of content.


https://developer.apple.com/library/prerelease/ios/samplecode/PageControl/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007795

Hello again donarb.


Admittedly I started my project out as a book style app (I think I mentioned this before so I won't go into this much) but I found that I couldn't stop the sound of an animation if the user turns the page before the animation finished. Nor could I have the app's plot split 3 different ways (the hero of the story at one point is confronted with 3 choices and he must make a choice and so the story has 3 different endings).


So seeing the page based template wouldn't meet these 2 challenges, I abandoned the page based template altogether and switched to the present model. It turns out that I don't have to worry about the number of view controllers (my app is actually a little easier on the memory using my new way of carrying out this project than when I carried out the page based approach) so I am sticking to what I have now. It works with out any problems and I am doing so much with it (animation and sound, taking a video feed of the user through the iPad cam and putting their image on one of the pages, and other unconventional things as well) I don't want to start from scratch.


I looked at the PageControl sample you provided the link to some time ago and it was interesting but as I wrote above, I am not going in that direction.


I hope you don't think I'm being stubborn here and I do appreciate your input.


JR


There is some merit to the "if it ain't broke, don't fix it" philosophy. If you're pretty far on in your project then it might not be worth changing at this point. But as I think I said in the other thread, it would be better to have a small number of VCs that know how to do a flexible layout. Maybe pass the VC an object, or some JSON or XML or something, that describes the layout of panels and the content of each panel. It's definitely easier to support and extend in future. Suppose you get all 100 pages done and now a new SDK comes out and you have to make a change to every one of those 100 VCs for compatibility. Not fun.


Anyway, as to a limit on number of VCs, I think the only limit that would apply is the maximum size of the executable portion of the binary (50 or 60 MB per slice nowadays I think?). That doesn't include your assets (sound and graphics).


(p.s. I don't know much about sound but stopping it when the page turns should be possible with any configuration of view controllers.)

No, I understand, we all get sort of wrapped up in our designs at the beginning, always trying to code as specific as possible to match the task at hand. But as you code more and more, you start to see that abstraction and genericity increases your ability to get more done with less code.


That's what I like about programming, I've been doing it for 30 years and still there's always something new to learn.

ahhh donarb, you make me feel better by saying that.


Yes, at this stage of the game I just want to get it up running on my iPad and then passing Apple's scrutiny and seeing it up on the app store. It's running on my iPad now, wish me luck on the latter 2 stages.


I started for this goal of creating apps 5 years ago. Never got into programming before. Worked from books like the 'For Dummies's' series. For 3 years it was like digging a bottomless pit. Then I finally found a school that taught a crash couse on Objective C. I took it and then I went from groping in the dark to dimly seeing what I was doing. My instructor looked at my plans for this app and thought it was quite original. He told me I would have to use classes that were ment for one type of application and apply them in ways that they weren't coded for. (like using the cam in the iPad for a page in my comic book rather than a camera app). He told me that what I was trying for was 'beyond advanced'. For a small fee, he helped me with the code after the course and I am glad he did. Looking at the thousands of lines of code which are now worked out I know it would take me years to get to this point. It is almost done now. I'm just cleaning up a few finicky details.


The most important thing is that I now enjoy coding. I like organising it and formating it and making comments that explain everything. Now I find that if I spend a day doing something else, I don't like it. It's addictive. And that's just what I'm looking for.


JR


Is there a limit to the number of View Controllers for an app?
 
 
Q