2009-09-22 3 views
2

Я реализовал этот ниже код.Проблемы с галочкой в ​​UITableViewCell

UITableViewCell *cell = [tableView1 cellForRowAtIndexPath:indexPath]; 
UITableViewCell *cell2 = [tableView1 cellForRowAtIndexPath:oldIndexPath1]; 

cell.accessoryType = UITableViewCellAccessoryCheckmark; 
cell2.accessoryType = UITableViewCellAccessoryNone; 
oldIndexPath1 = indexPath; 

Но если я выберу и сниму галочку, тогда я больше не могу выбирать галочку.

Вы можете мне помочь?

+2

бы помочь, если вы разместили код в didSelectRowAtIndexPath(). – Jordan

ответ

6

Я думаю, вы сбиваете с толку действие смены чека от одного к другому и действие переключения только на одну ячейку.

Предполагая, что вы хотите только одну ячейку отмеченных, вы можете сделать следующее:

+(void)toggleCheckmarkedCell:(UITableViewCell *)cell 
{ 
    if (cell.accessoryType == UITableViewCellAccessoryNone) 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    else 
     cell.accessoryType = UITableViewCellAccessoryNone; 
} 

// tableView:didSelectRowAtIndexPath: 

UITableViewCell *cell = [tableView1 cellForRowAtIndexPath:indexPath]; 
UITableViewCell *cell2 = [tableView1 cellForRowAtIndexPath:oldIndexPath1]; 

// Toggle new cell 
[MyController toggleCheckmarkedCell:cell]; 
if (cell != cell2) // only toggle old cell if its a different cell 
    [MyController toggleCheckmarkedCell:cell2]; 
oldIndexPath1 = indexPath; 
Смежные вопросы