方法函数
/**
* 返回当前视图的控制器
*/
- (UIViewController *)viewController {
for (UIView* next = [self superview]; next; next = next.superview) {
UIResponder *nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)nextResponder;
}
}
return nil;
}
说明
我在开发中,我将view和viewController分别写在不同的类中,当view中的滑动视图被点击时,我需要跳转到一个详细界面,XYRDetailViewController就是我需要跳转的详细界面,下面是详细的代码,你们主要是看方法函数里面的内容:
我的应用代码:
#pragma mark -SDCycleScrollViewDelegate
/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
NSLog(@"%ld",(long)index);
XYRDetailViewController *view=[[XYRDetailViewController alloc]init];
[[self viewController].navigationController pushViewController:view animated:YES];
}
/**
* 返回当前视图的控制器
*/
- (UIViewController *)viewController {
for (UIView* next = [self superview]; next; next = next.superview) {
UIResponder *nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)nextResponder;
}
}
return nil;
}
(有什么看不懂的可以在评论给我说!)