how to apply check mark on table view in iphone using objective c?

后端 未结 2 823
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-14 00:02

i m trying for apply for check mark in table view, but it is not working, if i checked again at that cell again then check mark apply. but not apply at new selected cell. a

2条回答
  •  佛祖请我去吃肉
    2021-01-14 00:36

    Do you mean that the checkmark doesn't apply when you choose the first line at the first time? You can add an else sentence to the code, but it wastes some time when running the code.

    if (newRow != oldRow)
    {
        UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;
    
        UITableViewCell *oldCell = [tableView cellForRowAtIndexPath: lastIndexPath]; 
        oldCell.accessoryType = UITableViewCellAccessoryNone;
    
        lastIndexPath = indexPath;  
    }
    else
    {
        UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;
        lastIndexPath = indexPath;
    }
    

提交回复
热议问题