UIView如何通过nextResponder响应链查找到所属的ViewController

https://stackoverflow.com/questions/1372977/given-a-view-how-do-i-get-its-viewcontroller


Objective-C category:

@interfaceUIView(mxcl)-(UIViewController*)parentViewController;@end@implementationUIView(mxcl)-(UIViewController*)parentViewController{UIResponder*responder=self;while([responder isKindOfClass:[UIViewclass]])responder=[responder nextResponder];return(UIViewController*)responder;}@end

你可能感兴趣的:(UIView如何通过nextResponder响应链查找到所属的ViewController)