2014-01-22 3 views
2

UITableView 행을 업데이트하는 데 문제가 있습니다. 내 tableView에서는 단 하나의 행만 선택할 수 있습니다 (두 개의 섹션이있을 수 있습니다). 따라서 사용자가 행을 선택할 때이 섹션의 다른 행을 프로그래밍 방식으로 선택 취소합니다. 선택 취소 된 행이 표시되면 모든 것이 작동합니다. 선택 취소 된 행이 표시되지 않으면 계속 선택됩니다. 그러나 didDeselectRowAtIndexPath이이 행에 호출됩니다. 왜? 이 문제를 해결하는 방법?보이지 않는 행 선택 취소

- (NSIndexPath*)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    // It is predefined group - only one row in section cab be selected 
    // Deselect other rows in section 
    for (NSIndexPath * selectedIndexPath in tagTableView.indexPathsForSelectedRows) { 
     if (selectedIndexPath.section == indexPath.section) { 
      [self tableView:tableView didDeselectRowAtIndexPath:selectedIndexPath]; 
      [tableView deselectRowAtIndexPath:selectedIndexPath animated:YES]; 
     } 
    } 

    return indexPath; 
} 

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tagTableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone; 
} 

답변

1

셀의 선택된 상태는 UITableViewCell에 저장되어서는 안되며 셀을 채우는 개체 (모델)에 저장되어서는 안됩니다.

테이블 셀은 재사용되므로 거기에 상태가 채워진 모델의 마지막 상태를 나타냅니다. select indexPath의 배열을 유지하는 셀을 채우는 객체에서 선택된 상태를 유지해야합니다.

-tableView:cellForRowAtIndexPath:에있는 해당 셀의 올바른 상태를 설정하십시오. 객체를 모델링하는 경우 선택된 상태를 유지하면 해당 속성에 따라 상태를 설정하거나 select indexpaths로 배열을 유지하는 경우 경로가 배열에 있는지 확인하고 그에 따라 상태를 설정합니다.

+0

보이지 않는 행을 선택 취소 할 수없는 경우 UIKit에 버그가 있습니다. 그런 다음에 붙어 있습니다. – Andy

관련 문제