自定义代理方法不调用

今天写了个代理方法,代理也设置了,但是点击按钮时,按钮点击事件相应了,但是里面的代理却显示为空,就很郁闷,是哪的原因呢?

RecentCell

- (IBAction)clickMinsuButton:(UIButton *)sender {

    if ([self.delegaterespondsToSelector:@selector(clickMinsuNameRecentCell:)]) {

        [self.delegateclickMinsuNameRecentCell:self];

    }

}


但是在控制器也设置代理了呀

PlanViewController


    self.recentCell = [[RecentCellalloc] init];

    CommonAdapter *commonAdapter = [[CommonAdapteralloc] initCommonAdapterWithTableview:self.planTableViewcell:self.recentCelldatas:self.recentArray];

    self.recentCell.delegate =self;

    self.commonAdapter = commonAdapter;

    [commonAdapter refresh];

//下面方法不调用

#pragma mark - RecentCellDelegate

- (void)clickMinsuNameRecentCell:(RecentCell *)cell

{

    MinsuDetailTableVC *minsuDetailTableVC = [[MinsuDetailTableVCalloc] init];

    minsuDetailTableVC.hidesBottomBarWhenPushed =YES;

    [selfpresentViewController:minsuDetailTableVCanimated:YEScompletion:^{

        

    }];

    

}

待我细细看下代码,发现问题在于

self.recentCell = [[RecentCell allocinit]; 

此时的recentCell是空的,并没有任何界面,而在适配器里面才显示了,所以,考虑应该在cell有

界面,点击时才会相应,所以就做了修改

CommonAdapter

@property (nonatomic,strong)UIViewController<RecentCellDelegate> * showViewController;



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [[self.cellclass] cellWithTableview:tableView];

    //四边多余的区域

    self.tableView.contentInset =UIEdgeInsetsZero;

    if ([[self.cellclass] isSubclassOfClass:[RecentCellclass]]) {

        RecentCell *recentCell = (RecentCell *)cell;

        recentCell.delegate =self.showViewController;

    }

    return cell;

}



PlanViewController

self.recentCell = [[RecentCellalloc] init];

    CommonAdapter *commonAdapter = [[CommonAdapteralloc] initCommonAdapterWithTableview:self.planTableViewcell:self.recentCelldatas:self.recentArray];

    commonAdapter.showViewController =self;

     self.commonAdapter = commonAdapter;

    [commonAdapter refresh];


#pragma mark - RecentCellDelegate

- (void)clickMinsuNameRecentCell:(RecentCell *)cell

{

    MinsuDetailTableVC *minsuDetailTableVC = [[MinsuDetailTableVCalloc] init];

    minsuDetailTableVC.hidesBottomBarWhenPushed =YES;

    [selfpresentViewController:minsuDetailTableVCanimated:YEScompletion:^{

        

    }];

    

}


代理方法调用了,完美的解决了问题,OK。。。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值