UITableViewCell Accessory Type Checked on Tap & Set other unchecked

后端 未结 9 2297
小蘑菇
小蘑菇 2020-12-03 03:02

I am confused a little bit about settings table view cell accessories.

I have fixed two sections in my table

  • Home
  • Office

What I

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 03:39

    A shortest and easiest way to implement logic for checkmark in selected row only.....


    1.Create a global object of NSIndexPath..

    selectedIndexPathForCheckMark= [[NSIndexPath alloc] init];
    

    2.In didSelectRowAtIndexPath..

    //Assiging selected indexPath to the declared object

    selectedIndexPathForCheckMark = indexPath;  
    [tableView reloadData];
    

    3.in cellForRowAtIndexPath..

    if ([selectedIndexPathForCheckMark isEqual:indexPath]) {
        [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
    }else {
        //setAccessoryType None if not get the selected indexPath
        [cell setAccessoryType:UITableViewCellAccessoryNone];
    }
    

提交回复
热议问题