didSelectRowAtIndexPath中改变自定义Cell属性问题

来源:互联网 发布:入住淘宝商城 编辑:程序博客网 时间:2024/06/05 16:22

今天翻了一个很低级的问题,而这个问题还让我找了很长时间才发现。
我在自定义cell中定义了一个属性

@property (assign, nonatomic) BOOL isChecked;

并且重写了它的set方法实现了内部一个属性改变

- (void)setIsChecked:(BOOL)isChecked{    _checkBoxView.checked = isChecked;}

当我改变自定义cell中的被选中状态时发现改变不了

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    [tableView deselectRowAtIndexPath:indexPath animated:YES];    AddPartnerTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];    FMLog(@"isChecked1:%d",cell.isChecked);    cell.isChecked = !cell.isChecked;    FMLog(@"isChecked2:%d",cell.isChecked);}

但是我发现内部是改变了。
后来无意中想起来重写这个方法还需要

- (void)setIsChecked:(BOOL)isChecked{    *_isChecked = isChecked;*    _checkBoxView.checked = isChecked;}

加上**中间着一行就行了。低级问题用于警醒。

阅读全文
0 0
原创粉丝点击