2015-01-19 4 views
0

다른 제목 표제에 대한 체크 표시를 통해 UITableView에 필터를 구현하고 있습니다.같은 화면으로 돌아 가면 UITableView의 체크 표시가 사라 집니까?

선택한 셀에 따라 쿼리가 로컬 데이터베이스에서 실행되고 결과가 나타납니다. 배열에 필터 결과를 저장하고 을 전달하고이 배열을 다른 uitableviewview에 밀어 넣어 결과를 표시합니다.

모달 세구를 사용하여 필터 화면으로 이동합니다.

하지만 문제는 필터 화면으로 돌아 가면 선택한 체크 표시가있는 셀이 사라집니다.

다음은 행을 선택하는 내 코드입니다 :

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    long sec = [indexPath section]; 
    if(sec==0){ 
    if(cell.accessoryType == UITableViewCellAccessoryNone) { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
     [sportsSelectedRows addObject:indexPath]; 
    } 
    else { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
     [sportsSelectedRows removeObject:indexPath]; 
    } 

    } 
    else if(sec==1){ 
     if(cell.accessoryType == UITableViewCellAccessoryNone) { 
      cell.accessoryType = UITableViewCellAccessoryCheckmark; 
      [areaSelectedRows addObject:indexPath]; 
    } 
     else { 
      cell.accessoryType = UITableViewCellAccessoryNone; 
      [areaSelectedRows removeObject:indexPath];} 
    } 
else if(sec==2){ 
    cell.tag = indexPath.section; 
    for (UITableViewCell *cell in [tableView visibleCells]) { 
      if (cell.accessoryType != UITableViewCellAccessoryNone && cell.tag == indexPath.section) { 
       cell.accessoryType = UITableViewCellAccessoryNone; 
      } 
     } 
    if(cell.accessoryType == UITableViewCellAccessoryNone) { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
      [daySelectedRows removeAllObjects]; 
      [daySelectedRows addObject:indexPath]; 
     } 
     else { 
      cell.accessoryType = UITableViewCellAccessoryNone; 
      [daySelectedRows removeObject:indexPath];} 
    } 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 

당신은이 문제를 해결하는 데 도움이 수 없습니다.

+0

가능한 복제본 [UINavigationController 하위 화면에서 돌아 왔을 때 UITableView 선택된 행을 어떻게 유지합니까?] (http://stackoverflow.com/questions/6795214/how-do-i-maintain-the-uitableview-selected -row-when-returning-from-a-uinavigatio) – jlehr

+0

감사합니다 @jlehr 나는 이것을 점검하고 다시 연락 할 것입니다. –

답변

0

인사이드 didSelectRowAtIndexPath: 항목/경로가 선택되거나 선택되지 않아야한다는 사실을 기록하는 것 외에는 아무 것도하지 않습니다. 액세서리 취급을 cellForRowAtIndexPath:으로 옮깁니다.

+0

'didSelectRowAtIndexPath'에서 선택한 셀의 액세서리 유형을 업데이트하는 것이 완벽합니다. 체크 표시를 토글하는 것만으로 행을 다시로드하는 것보다 훨씬 효율적입니다. – rmaddy

+0

나는 현재 선택된 셀에 대해'tableView : didSelectRowAtIndexPath :'를 사용하고 화면 상에 나타날 행에 대해 올바른 stuf를 설정하기 위해'tableView : willDisplayCell : forRowAtIndexPath :'를 사용하고자한다. – vikingosegundo

+0

@rmaddy, 답장을 보내 주시면 감사하겠습니다. 예제를 제공하거나 코드를 편집 해 주시겠습니까? –