首页 > 移动平台 > 详细

ios 自定义cell类中获取当前controller push

时间:2015-10-29 12:48:33      阅读:559      评论:0      收藏:0      [点我收藏+]

有时候在自定义cell的过程中,当cell中又button的时候,把button的点击时间写在cell中的时候,需要获取到cell的父视图控制器然后push,可以自建一个类,命名为:

GetCurrentNaviGationController,在.h文件 中提供一个类方法

+(UIViewController *)viewController:(UIView *)view;

 

然后在.m中实现

+(UIViewController *)viewController:(UIView *)view{

    /// Finds the view‘s view controller.

    // Traverse responder chain. Return first found view controller, which will be the view‘s view controller.

    UIResponder *responder = view;

    while ((responder = [responder nextResponder]))

        if ([responder isKindOfClass: [UIViewController class]])

            return (UIViewController *)responder;

    // If the view controller isn‘t found, return nil.

    return nil;

}

 

然后在想调用的cell中引入头文件,然后调用

[[GetCurrentNaviGationController viewController:self].navigationController pushViewController:controller animated:YES];

ios 自定义cell类中获取当前controller push

原文:http://www.cnblogs.com/damnbird/p/4919837.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!