2012-03-23 107 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:didSelectRowAtIndexPath'而不是'tableView:didDeselectRowAtIndexPath'中。 – warrenm 2012-03-23 17:11:02

+0

什么?你知道你把同样的方法粘贴了两次吗? :P – 8vius 2012-03-23 19:20:29

+0

仔细阅读。 – warrenm 2012-03-23 19:29:23

回答

2

看来,你在tableView:didDeselectRowAtIndexPath执行你的逻辑,但默认情况下,这个方法不叫,直到小区选择的变化。如果您将其放入tableView:didSelectRowAtIndexPath(注意名称略有不同),则在单元被轻敲时即可获得回叫,并且附件视图应立即显示。

相关问题