我有一個約有20行的UITableView
。我也使用複選標記附件來標識所選內容。我現在面臨的問題是,當我滾動時(這裏我選擇了多行),選擇會變得混亂。所以滾動後所選的checkmark
已經消失。任何人都可以幫我找到一種方法嗎?在didSelectRowAtIndexPath:
如何跟蹤UITableView中所有選定單元格的索引
NSMutableDictionary *rowDict = [tableList objectAtIndex:[indexPath row]];
if([tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark)
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}
else
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
checkedIndexPath = indexPath;
NSLog(@"the checked psths are :%@",checkedIndexPath);
}
而在cellforrowatIndexpath
我用
if([self.checkedIndexPath isEqual:indexPath])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
但這僅適用於單一選擇。我應該怎麼做多選?
所以你說要怎麼做didSelectRowAtIndexPath方法,然後在的cellForRowAtIndexPath數組或取消選中創建單元正確匹配嗎? – rashii
是的,你說得對 – Ilanchezhian