UIView如何通过nextResponder响应链查找到所属的
2017-07-03 本文已影响29人
思考的小妮子
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