Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Ben McCloskey
699 PointsHow to load a different index of an array of objects that lives in another view?
I'm stuck on a problem in an iOS app, and I was wondering if anyone could maybe point me in the right direction.
Basically, I've followed several iOS tutorials, and managed to put together a very simple app that shows a 'page' of a book (illustration as the background and text on top). This data is stored in objects that are put together in an array in the main view. I'm simply trying to reuse the page view to "turn the page" by swiping left and right. I got the swiping part figured out, but the main array that holds the pages is what is stumping me.
I use prepareForSegue on the main view, then load up the page object (in the page view) based on an array in the main view, so how can I move to a different index in the the pages array if it is still over in the main view?
Seems like a simple problem, but maybe I don't yet understand delegates enough? Seems like it has something to do with that.
I'd like for there to be a page turn transition as well. Not sure if that's possible when re-using the same view.
Any pointers would be appreciated.
1 Answer
Amit Bijlani
Treehouse Guest TeacherThe Page-Based application template provides the boiler plate code to facilitate this functionality. All you have to do is change the data and the view.
Ben McCloskey
699 PointsBen McCloskey
699 PointsThank you for the reply, Amit! I've looked at the page-based application template a lot, and it does provide an example of the page turn that I will try to use, but I'm still stuck on how to change the index of the array and reload the page.
Mine has a "main" ViewController (initial scene, which will hold the main menu), then I have a button that takes you to the PageDetailViewController. I kinda based the layout of it on your Puns app (but not in a list view). It works great so far, but I just can't quite grasp how I will change the current view in the PageDetailViewController.m file to show another index of the array of objects that is in the ViewController.m file.
Amit Bijlani
Treehouse Guest TeacherAmit Bijlani
Treehouse Guest TeacherCan you share your project via Dropbox or something similar?
Ben McCloskey
699 PointsBen McCloskey
699 PointsHere you go: https://www.dropbox.com/sh/t2f3sq7w7oe3f4y/YaNCX2F0W-
Thanks for taking the time!
Amit Bijlani
Treehouse Guest TeacherAmit Bijlani
Treehouse Guest TeacherYou are trying to do manually what could easily be achieved by using UIPageViewController which provides the navigation and page curl transitions. The Page-Based application template uses it too.
Ben McCloskey
699 PointsBen McCloskey
699 PointsAmit, thank you for looking at it.
I now have it working using UIPageViewController, yay! Now, I need to figure out how to add a main menu for options, instead of starting the page view right away.
Thanks again for your help!