I’ve run into a bit of a brick wall with an app I’m working on and I just can’t get my head around how to jump to a specific view controller in a navigation controllers stack.
So to give an overview of the structure of the app. I’m using Storyboards and Segues for navigation between views.
Home Screen – this pulls a list of the 4 latest job updates from the server and displays them in a table and has a button which displays the UINavigationController modally.
UINavigationController
Job List – pulls a list of all current jobs from the server and displays them in a table. On selecting a cell, jobid is set in Job details during prepareForSegue:, which is then pushed onto the stack.
Job Details – pulls all the details (description, photos etc.) of the job and displays them.
So navigating the jobs via the home screen button > Job List > Job Details isn’t a problem and works perfectly.
What I can’t figure out is how to jump to the details of a specific job when selecting one of the latest job updates on the Home Screen.
I hope I’ve explained it enough. Any help would be greatly appreciated.
Thanks.
Make a couple of properties in your JobListViewController:
When you present modally from homescreen, if a job is selected pass it to initialisedWithSelectedJob in JobListViewController:
Then in your JobListViewController’s viewDidLoad:
You have to reset initialisedWithSelectedJob so that you can return here from the JobDetails screen without being bounced straight back again. ).
In your JobListViewController’s prepareForSegue you can pass on the selectedJob id as you do already.
update
This way, you will return from Job Detail to JobListViewController. The movement from home screen -> job list screen -> job detail screen will be consistent regardless whether you select a job on home screen or list screen.
If you follow
0x7fffffff‘s answer then the navigation is quite different whether you select a job from the home screen or job list screen.I am wondering whether you should rethink your design a little – having your job list on both the home screen and in JobListViewController is perhaps a little redundant?