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
Derek Medlin
6,151 PointsAccessing Container View
I know how to access container view methods.
-(void)clearTableView{
for (UIViewController *childViewController in [self childViewControllers])
{
if ([childViewController isKindOfClass:[OutputTableViewController class]])
{
//found container view controller
OutputTableViewController *outputTableViewController = (OutputTableViewController *)childViewController;
[outputTableViewController clearTableView];
self.tabBarController.selectedIndex = 0;
}
}
}
But what if there is a UINavigationController between the main view and the container view? I know I could embed the navigation controller in the main view but would like to know how to do it this way please. Thanks
Derek Medlin
6,151 PointsSorry about that. Basically all i'm trying to do is perform methods located in the child view, from the parent view. Lets say you have a UIViewController with a UITableViewController in the container view. With the above code that allows me to call methods from the UITableViewController in it's parent view BUT I have a navigation controller in between the UIViewController. I just want to know how to access methods located in child view's implementation file from the parent view with a navigation controller embed in the child view. I'm so sorry that i'm butchering this question. I'm learning and having a hard time with the right terminology.

Derek Medlin
6,151 PointsI suck at markdown, thought i could upload a pic example.
Amit Bijlani
Treehouse Guest TeacherUpload the image to imgur.com and then edit that link because it points to your desktop right now.
Derek Medlin
6,151 Pointslets try this.......
Derek Medlin
6,151 PointsYeah i figured it out, i thought that it wouldn't work.
Amit Bijlani
Treehouse Guest TeacherSo let's say your container view is your "Parent View Controller" and the table view is a "Child View Controller". Are you trying to transition from the Parent to the Child when a user clicks on a cell?
Derek Medlin
6,151 PointsI accidentally posted that reply as the answer....anyways the above code works if you take out the navigation controller. i just want to modify the code somehow to find the OutputTableViewController
1 Answer
Derek Medlin
6,151 PointsTo make this simple, when I click "Item" button in the toolbar, I want the tableview to clear. The navigation controller is what broke my above code because I can't find the OutputTableViewController anymore. The navigation controller is out of the scope of this question. I have it for navigation when a user clicks, like you said, to an "Estimate Breakdown" all of that isn't really important so I left it out of the question.
So in the left controller for the action of the tool bar i want to write something like
[outputTableViewController clearTableView];
and in the right controller (the table view) the table is cleared.
Sorry i'm having trouble explaining it's totally ok if you can't answer, I'll just keep learning and figure it out.
Amit Bijlani
Treehouse Guest TeacherHere are a few suggestions:
- If the left one is the main view then I would embed that view controller in a navigation controller and not the table view.
- You can use a notification: http://teamtreehouse.com/library/ios-5-foundations/notifications
Derek Medlin
6,151 PointsYeah, I didn't show all of what goes on, the navigation controller was for the cells to navigate from when a use clicked to another view that wasn't in the picture. The only reason I did that was so the toolbar would stay at the top and not scroll with the tableview. It may have been a cheap way of doing it but thats only way i could get it to to work but after thinking about it, I can live with it that way (it was the way i had it first anyways).
Thanks I actually didn't think about that, but since i'm now going to embedding the view controller instead of the tableview then my above code works.
Thanks a lot for the info and time! You guys have the best videos and keep them coming! I've learned a lot in just a little bit.

Amit Bijlani
Treehouse Guest TeacherAmit Bijlani
Treehouse Guest TeacherIt is unclear what you are trying to achieve. Can you provide some background information?