2012-03-23 13 views
0

選択したセルにチェックマークを付けるUITableViewを作成しようとしていますが、チェックマークは追加されますが、すぐには表示されません。異なる行。どのように私はそれを瞬時にすることができますか?これは私のコードです:iOS - 選択後にUITableViewCellにチェックマークが表示されない

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Contact"; 

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

    NSLog(@"%@", [[self.contacts objectAtIndex:indexPath.row] valueForKeyPath:@"TwitterFriend.screen_name"]); 
    cell.textLabel.text = [[self.contacts objectAtIndex:indexPath.row] valueForKeyPath:@"TwitterFriend.screen_name"]; 
    if ([self.selectedContacts containsObject:[self.contacts objectAtIndex:indexPath.row]]) { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    } else { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [self.selectedContacts addObject:[self.contacts objectAtIndex:indexPath.row]]; 
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; 
} 
+2

'tableView:didDeselectRowAtIndexPath'の代わりに' tableView:didSelectRowAtIndexPath'にそのロジックを入れてみることができます。 – warrenm

+0

何ですか?あなたは同じ方法を2回ペーストしたことを知っていますか? :P – 8vius

+0

もっと詳しくお読みください。 – warrenm

答えて

2

あなたがtableView:didDeselectRowAtIndexPathであなたのロジックを実行していることが表示されますが、デフォルトでは、この方法は、セルの選択が変更されるまで呼び出されません。 tableView:didSelectRowAtIndexPath(若干異なる名前に注意してください)に入れる代わりに、セルがタップされるとすぐにコールバックを取得し、アクセサリビューがすぐに表示されます。

関連する問題