ios--随笔二

//前提:在UITableView中,分4个section,每个section中只有一行(自行脑补界面)

//在UITableView中,单击记录cell0后,改变cell0原来的状态;点击cell1后,cell0恢复原来的状态,cell1的状太改变。

//其中的NSIndexPath *lastIndexPath为实例变量

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    int newSection = (int)[indexPath section];//点击某一行后,newSectioon记录下点击某一section

    int oldSection = (lastIndexPath != nil) ? (int)[lastIndexPath section] : -1;//当第一次点击section时,lastIndexPath = nil,oldSection = -1

    if (newSection != oldSection){

        CorrectiveFeedbackCell *newCell = [tableView cellForRowAtIndexPath:indexPath];//自定义的CorrectiveFeedbackCell,可以根据实际情况定义:newCell为点击的newSection的那一行

        newCell.mainImageView.image = [UIImage imageNamed:@"pay_success_small"];//改变newCell的状态

        CorrectiveFeedbackCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];//第一次点击时没有创建oldCell;

        oldCell.mainImageView.image = [UIImage imageNamed:@""];//

        lastIndexPath = [indexPath copy];//将点击的某行,拷贝到lastIndexPath

    }

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    [tableView reloadData];

}

   后记:感觉这个方法是直接改cell的状态,好像不是很符合MVC设计模式,当然这个方法比较适合写静态又比较小改变的TablView(本人是小白,笔记中若有错误,欢迎指出,大家一起探讨探讨)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值