2011-07-05 7 views
0

UICTableView의 선택된 항목을 겹쳐 쓰기 확인란의 NSMutableDictionary에 저장해야합니다. 그래서 나는 다음과 같이한다.UITableView 선택한 항목 저장

NSMutableDictionary * selDict;// - instance variable 

    ... 
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

     if ([selDict objectForKey:indexPath]) 
      [selDict setObject:[NSNumber numberWithBool:FALSE] forKey:indexPath]; 
     else 
      [selDict setObject:[NSNumber numberWithBool:TRUE] forKey:indexPath]; 

     [[self tableView]reloadData]; 

    } 

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

     static NSString *CellIdentifier = @"Cell"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
      [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
     } 

     if ([selDict objectForKey:indexPath]) 
      cell.accessoryType = UITableViewCellAccessoryCheckmark; 
     else 
      cell.accessoryType = UITableViewCellAccessoryNone; 
     ... 

     return cell; 
    } 

그러나 체크 된 항목 만 설정하고 더 이상 작동하지 않는다.

+0

더 이상 작동하지 않는다는 것은 무엇을 의미합니까? 또한 [[[self tableView] reloadData] 대신에 [[self tableView] reloadRowsAtIndexPaths : [NSArray arrayWithObject : indexPath] withRowAnimation : UITableViewRowAnimationNone]'을 사용하는 것이 더 좋다. (전체 테이블을 다시 읽어들이는 지점이 없다) –

+0

팁 주셔서 감사. 그것은 또한 나를 위해 작동합니다. –

답변

2

당신은 당신이 지금하고있는 것은 개체가 존재하는지 여부를 확인하고 있습니다

if ([selDict objectForKey:indexPath]) 

if ([[selDict objectForKey:indexPath] boolValue]) 

에 변경할 수 있습니다. nil 일 때 한 번 작동하지만 이후에는 작동하지 않습니다.