Accessing parent view of current view - iOS

Naveed Rafi picture Naveed Rafi · Jan 27, 2011 · Viewed 49.1k times · Source

When I want to access the parent UIView of current UIView I declare object of parent UIView in current UIView and access it by assigning the parent UIView object to current view's object property.

Is there any way to get rid of this and directly call the parent view's methods or properties?

I also tried (parentView *) self.view.superview but didn't help.

It gives error while calling function for this object as

[UIVIew unrecognized selector......

Answer

omz picture omz · Jan 27, 2011

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