Search code examples
iosobjective-cuitableviewuiviewcontrollersuperview

Check if superview is UITableViewController UIViewController?


I have a custom class I created. Is there a way to check if it's superview is a UITableViewController, or a `UIViewController?


Solution

  • You can access nextResponder property of your superview

    [self.view.superview nextResponder];

    or if in custom class

    [self.superview nextResponder];

    and check throw isKindOfClass if this is the view controller type you're looking for.

    Apple's documentation of -[UIResponder nextResponder]:

    UIView implements this method by returning the UIViewController object that manages it (if it has one) or its superview (if it doesn’t)