简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM