Accessing parent view of current view - iOS Accessing parent view of current view - iOS ios ios

Accessing parent view of current view - iOS


If you're calling this directly from a UIView (and not a UIViewController), it should be self.superview instead of self.view.superview.


@ Naveed: This is the common code u can use to any view whether it is parent or child view, Just change button name which u want to press and the view name on which u want to go. For example on back button press u want to go on library view then write this code -

-(IBAction)backButtonPressed:(id) sender {        llibraryView *libraryview=[[libraryView alloc] initWithNibName:nil bundle:nil];    libraryview.modalTransitionStyle=UIModalTransitionStyleCoverVertical;    [self presentModalViewController:libraryview animated:YES];     [libraryview release]; }

Let me know whether ur problem is solved or not.


What I can think is that you want to call the viewcontroller's method from your view, which you added to the viewcontroller's view.

Now you have two options from here, either you set your view controller your view's delegate and then call your viewcontroller's method by [delegate performSelector:] approach.

The other approach is you access your view's superview, and then get it's controller. You can not do that directly, coz if you could do that it would defeat the entire purpose of MVC.

But, still there is a way out, here you go:-

Get to UIViewController from UIView?

Hope, this helps you.