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];
}
你可以尝试把这个逻辑放在'tableView:didSelectRowAtIndexPath'而不是'tableView:didDeselectRowAtIndexPath'中。 – warrenm 2012-03-23 17:11:02
什么?你知道你把同样的方法粘贴了两次吗? :P – 8vius 2012-03-23 19:20:29
仔细阅读。 – warrenm 2012-03-23 19:29:23