how can i access a parent view controller's view from a child view controller?
To access the parent View controller you can use self.parentViewController
. Once you have it you can access its view simply by using its view
property
Note to those using iOS 5.x+
self parentViewController
now returns nil
. You will now have to use self presentingViewController
to achieved the same result. See this blog post for more information and additional work arounds for upgrading your code base: http://omegadelta.net/2011/11/04/oh-my-god-they-killed-parentviewcontroller/
here's what worked for me:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSString * segueName = segue.identifier;
if ([segueName isEqualToString: @"child-view"]) {
ChildViewController * childViewController = (ChildViewController *) [segue destinationViewController];
[self addChildViewController:childViewController];
}
}