view中push或present

通常使用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];

0

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • /* UIViewController is a generic controller base class th...
    DanDanC阅读 1,853评论 0 2
  • 1、禁止手机睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa阅读 1,143评论 1 6
  • 有的时候需要在view上也需要调用push或者present推出新的页面的方法,可以使用以下三种。 1、block...
    常绿箩阅读 738评论 0 0
  • 昨天是在姨妈家的第三天,早上还是起的很早的,大概六点多就醒了,起来以后就先把手机视频关了,开了一晚上了,前晚因为看...
    坚志阅读 234评论 0 0
  • 天微亮 出门遛狗 想着今年 最强冷空气来了 穿上长袖长裤 一身汗回来 才发现温度 升了5度
    第一闲人阅读 174评论 0 0