2009-09-22 4 views
2

아래 코드를 구현했습니다.UITableViewCell의 체크 표시 문제

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

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

그러나 체크 표시를 선택했다가 선택 해제하면 체크 표시를 더 이상 선택할 수 없습니다.

나를 도와 줄 수 있습니까?

+2

이 도움이 될 것이다(). – Jordan

답변

6

당신은 수표를 다른 것으로 바꾸고 하나의 셀만 토글하는 동작을 혼란스럽게 생각합니다.

당신이 하나 개의 체크 표시 셀을 원하는 가정하면, 다음을 수행 할 수 : 당신은 didSelectRowAtIndexPath의 코드를 게시하는 경우

+(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;