iosobjective-cuiviewsuperview

Accessing parent view of current view - iOS


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......

Solution

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