Removing an Accessory View from a UITableViewCell When The Cell is Not Selected and maintaining between reloading views

泄露秘密 提交于 2019-12-08 17:37:28

Create a property in your .h file

@property (nonatomic,retain)NSIndexPath * checkedIndexPath ;

synthesize in your .m file

@synthesize checkedIndexPath;

write this code in your didSelectRowAtIndexPath method

if(self.checkedIndexPath)
{
   UITableViewCell* uncheckCell = [tableView
                                    cellForRowAtIndexPath:self.checkedIndexPath];
    uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}
if([self.checkedIndexPath isEqual:indexPath])
{
    self.checkedIndexPath = nil;
}
else
{
   UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    self.checkedIndexPath = indexPath;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!