封装的视图 有时会有点击事件,需要获取该视图所在的控制器调用方法,那么利用UIView的获取父视图的方法,获取父视图的响应者,判断是否为控制器
- (UIViewController*)getViewController {
for (UIView * superView = [self superview]; superView; superView = superView.superview) {
UIResponder * nextResponder = [superView nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)nextResponder;
}
}
return nil;
}
//博客仅为学习并记录,欢迎交流