Programmatically pushing from one view controller to the next.

Greetings.


I am creating a comic book using view controllers & accompanying classes for each page. When the user taps the right side of the page I use a simple push segue to move to the next page which slides in from the right. And if the user taps the left side of the page the previous page sides in from the left. To get it to do that I used a method rather than a push segue because if I use a push segue, the previous page will side in, but also from the right which is visually confusing to the user. That method is:

- (IBAction)goBackToD1Page5:(id)sender
  {
    [self.navigationController popViewControllerAnimated:YES];
 }


This works just fine until the end. Because at the end of the comic, I want it so when the user taps the right side of the page (there is an elongated invisible button there waiting to be tapped as in all the pages) the user sees an animation in the lower right side of the page and then the animation is finished, they are brought back all the way to the first page of the comic which effectively turns the plot of the comic into a loop.


So what I need is a method to do this. Not one that pops the present View Controller off the stack to reveal the previous page but one the brings the user to Page 1 of the comic (the very first page is the Cover page but I don't want the user to go there). Can anyone help me here. I've tried this and I've tried that but I am getting nowhere.


JR

There is popToRootViewControllerAnimated:. You can also programmatically set the contents of the view controller stack - just use setViewControllers:animated:.


Have you tested this setup on your least capable supported devices? How much memory are you using after pushing 100 (or 30 something, since you say you have different plot lines) VCs on the stack? Always pushing and never popping until you get to the end is NOT an efficient design. Which brings us back to the discussion in your other threads. 🙂

In addition, there is the concept of unwinding segues, allowing you to designate a specific view controller to jump back to. It's actually kind of slick since the view controller you're jumping from doesn't know about the destination view controller, you just say jump and the system walks back up the stack of view controllers to see which one is willing to accept the jump.


See tech note #2298 about Unwinding Segues.


https://developer.apple.com/library/ios/technotes/tn2298/_index.html

Hello junkpile.


I watch the memory usage as the app goes through all the pages (through the main plotline and then going back and forth on all 3 branches of the plot) and the memory usage does not increase. It is the more complicated animation near the beginning of the plot (page 4) that ups the memory usage. (an animation where the hero looks out at the viewer in horror and then the whole scene pivots around so you are looking at the hero from the back - over his shoulder - all this accompanied by a deep grinding sound a then the camera takes a live video feed so the user see themselves real time in the comic book with the hero of the comic staring up at them) this ups the memory usage to 570 MB. (When I finally have my app up on the app store, it will be for iPad Air 2s only.)


After this animation takes place there are other pages, some with even more things are happening than the one I described above, but the memory usage doesn't go up much at all, and sometimes goes down. It's as if the app sort of pushed into the available memory of my iPad Air 2 and then just stayed happily in that claimed area. It never goes above 570 MB.


As for your suggestion on using popToRootViewControllerAnimated: Won't that put the user to the very first page of the comic book? That would be the Comic book's cover and I don't want that. I want the user to be catapulted to page 1 (the page after the Cover page). You see on the last page of the first plot ending my hero dies and it is animated, then after the death animation finishes, the app should move to page 1 where he is born (the birth is animated as well) The plot of the first subplot is about the life/death/live cycle concept and you can see why I want the end of the first subplot to automatically loop back to the beginning of the plot.


I'm sorry if I'm a bit uncomprehending here, but I am a relative new to programming so please be patient.


JR


How do you plan on restricting your app to iPad Air 2s only? As far as I know that's not possible.


Given what you've said maybe an unwind segue is the way to go then, as donarb suggested. Either that or setViewControllers:animated: as I suggested, with just the two bottommost VCs on the stack.

Interesting point junkpile.


Maybe you are right. However, I am sure there are many apps made for an iPhone 6 that will not work on the 1st, 2nd or even 3rd generation models. Surely, to prevent users of the app store from being unhappy with an app that won't work well, Apple will allow the maker of the app to mention memory restrictions. I also recall an article that talked about the limits an app has when it comes to how much memory it can take up on the so-called hard disk in iPhones and iPads. They moved it up from 1GB to 3GB! (If my memory serves me correctly)


I have an iPhone 4s. Recently, I bought a jawbone UP 24. The app often crashes or shows other glitches on my older modle iPhone. I assumed that it was the age of my iPhone. So I bet that the situation of older models not being able to handle newer apps is common.


That said, I'll certainly look into the point you just made and the suggestion of the unwind segue (I remember reading about it a while ago) as well as the setViewControllers:animated: you wrote about.


Thanx again junkpile.


JR

Hey there junkpile.


I got the answer to your questions on how I am going to restrict access to the iPad Air only! I looked up a popular app Monument Valley on iTunes Preview on Apple's iTunes website and it states under the price and Category etc. Compatibility: And it then goes through the iOS version and the different types of devices that it will work on (in its case nothing older than iPhone 4). Then it lists the devices that it is optimised for. So it looks like I can say "Hey iPad Air only!" I have an iPad 2 and it almost works with that but it can't handle memory usage over 500 MB and as I said before it goes up to 570.


Any way, I as still looking up your other suggestions ( unwinding segues , etc.)


Just thought you would want to know.


JR

Programmatically pushing from one view controller to the next.
 
 
Q