Okay so i have done a tutorial that has me populating a TableViewController from the appDelegate.m file in this way.
UINavigationController *navController = (UINavigationController *) self.window.rootViewController;
MasterViewController *masterController = [navController.viewControllers objectAtIndex:0];
masterController.bugs = bugs;
I am attempting my own small app for some practice but the way i’m doing it my TableViewController is not the rootViewController. It is the next view after that. I am using storyboards to create my GUI, not sure if that is a needed to know thing.
Basically I have my object that has an member that is and array and I want to create the object in the appDelegate file and populate the TableViewController with the array from my object.
Here is some extra details:
I did was was suggested and replaced the 0 index with a 1 but i get this exception error
2012-10-07 21:34:23.785 EasyBudget[5257:f803] * Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘* -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]’
* First throw call stack:
(0x14b5022 0xeb5cd6 0x14a1644 0x20c8 0x16386 0x17274 0x26183 0x26c38 0x1a634 0x139fef5 0x1489195 0x13edff2 0x13ec8da 0x13ebd84 0x13ebc9b 0x16c65 0x18626 0x1efd 0x1e65 0x1)
terminate called throwing an exception
I understand the reason for the exception. For some reason my the Array that holds the different views from my navigation controller only has a 0 index. I’m just not sure how to fix this. I set my storyboard up in the way Navigation Controller -> ViewController (which is my root view relationship) -> Table View Controller (this is the view i’m trying to access). I added a bar button item with a push segue from my root view controller to the table view controller. When i built and ran before adding code everything worked I could push my button and it went from my view controller to my table view controller and i was able to push the back button the was automagically made by the navigation bar to get back to my view controller. I hope this was all done correctly. Any more help would be greatly appreciated.
That makes sense for the “tutorial” because the table view controller is the nav controller’s root view controller, so it’s always going to be available. I’m guessing that tapping a row in the table probably causes the app to transition to a detail view controller related to the tapped row, and that detail view controller is probably set up by the table view controller.
You can follow the same pattern in your app: have your app delegate do whatever’s necessary to set up the navigation controller’s root view controller, and then have that controller set up whatever view controller it transitions to. Since you’re using storyboards, a good place to do that is in your view controller’s
-prepareForSegue:sender:method — you can get the segue’s destination view controller in that method and pass over whatever data is necessary for the new controller (i.e. your table view controller) to do it’s thing.