美文网首页
自定义Cell上放Button, 然后实现Button的点击方法

自定义Cell上放Button, 然后实现Button的点击方法

作者: 不高冷的龙拾柒 | 来源:发表于2016-09-01 09:36 被阅读0次

    写项目的时候,遇到了个问题,如题(即自定义Cell上放Button, 然后实现Button的点击方法,push到下一界面),百度了下,没有得到任何有效的方法, 问了有经验的同事,同事给了句,找响应者.于是,解决了.想必也会有不少小程序员会要遇到这样的需求,代码奉上,希望能够帮到搜索到这一问题的人以帮助,少走一点弯路.(代码我可以教给你怎么写,天赋我是教不了,想知道为什么,或者什么的,自己去研究响应者好了,我是搞开发的,不是搞授课的,只追求实现.理论别找我!)废话不多说,开启正文:

    在tableViewCell.xib里拖拽Button,并将Button点击方法拖拽到cell.m里,在方法里写

    - (IBAction)ButtonAction:(UIButton *)sender {
        id responder = self.nextResponder;
        while (![responder isKindOfClass:[UIViewController class]] && responder != nil) {
            responder = [responder nextResponder];
        }
        UIViewController *rootVC = (UIViewController *)responder;
        MViewController *MVC = [[MViewController alloc] init];
        [rootVC.navigationController pushViewController:MVC animated:YES];
    }
    

    cell.m里要引头文件MViewController(你要push的VC).
    问题完美解决,如满意请给予个赞支持一下咯!

    相关文章

      网友评论

          本文标题:自定义Cell上放Button, 然后实现Button的点击方法

          本文链接:https://www.haomeiwen.com/subject/qpucettx.html