cell点击按钮崩的一种情况

 

这个错误表示:该类方法没有addBtnClick对应的方法;

 

bug的复现:创建一个cell,并且添加一个类方法来赋值,在方法中,给按钮添加一个点击事件(addBtnClick),但是,再实现这个方法时,我是用对象方法,所以会崩,应该改成类方法(即用 “+”):

+ (WDKAddFriendResultCell *)addFriendCellWithTableView:(UITableView *)tableView {

    WDKAddFriendResultCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WDKAddFriendResultCell"];

    if (cell == nil) {

        cell = [[[NSBundle mainBundle] loadNibNamed:@"WDKAddFriendResultCell" owner:nil options:nil] lastObject];

    }

    cell.addBtn.layer.borderColor = RGBA(0, 161, 176, 1).CGColor;

    cell.addBtn.layer.borderWidth = 0.5;

    [cell.addBtn addTarget:self action:@selector(addBtnClick) forControlEvents:UIControlEventTouchUpInside];

    return cell;

}

 

添加对应的方法:

-  (void)addBtnClick {

    [YZTools toastMake:@"不会崩" isPush:NO];

}------------------------这样是会崩的;

应该改写如下:

+ (void)addBtnClick {

    [YZTools toastMake:@"不会崩" isPush:NO];

}

posted @ 2016-07-15 10:27  一人前行  阅读(120)  评论(0编辑  收藏  举报