通常使用self.navgationController是在Viewcontroller里面调用的,但是有的时候需要在view上也需要调用push或者present推出新的页面的方法,那么可以使用以下三种。
1、block方法。
2、代理方法。
3、获取该View所在的Viewcontroller。【这个也是我要说的方法】
//获取View所在的Viewcontroller方法
- (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;
}
//使用方法:
[[self viewController].navigationController pushViewController:[yourViewController new] animated:YES];
本文详细介绍了在不使用self.navigationController的情况下如何在View上实现页面的推送和显示,包括block方法、代理方法以及获取当前View所处的ViewController的方法,并通过实例展示了如何使用这些方法来推动新的ViewController。
1342

被折叠的 条评论
为什么被折叠?



