0

当我滚动 tabview 单元格时,复选标记被隐藏。我该怎么办?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [[tableView cellForRowAtIndexPath:indexPath] setSelected:NO];

    FacebookFriend *friend = [self.fbFriendsFiltered objectAtIndex:indexPath.row];

    // Build list to invite
    if ( [self.fbFriendsInvited containsObject:friend.fid] ) {
        [self.fbFriendsInvited removeObject:friend.fid];
        NSLog(@"fbFriendsInvited:%@",self.fbFriendsInvited);
        [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryNone];
    } else {
        //if ( [self.fbFriendsInvited count] >= kSelectionLimit )
          //  return;

        [self.fbFriendsInvited addObject:friend.fid];
        [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
        NSLog(@"fbFriendsInvited:%@",self.fbFriendsInvited);
    }
}
4

2 回答 2

0

您需要在 cellForRowAtIndexPath 中添加以下代码

NSArray *array = [cell subviews];
for (int i = 0; i < [array count]; i++)
{
    if([[array objectAtIndex:i] isKindOfClass:[UIButton class]])
    {
        [[array objectAtIndex:i] removeFromSuperview];
    }
}

之后——

 if (cell == nil) 
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
于 2013-07-01T12:01:11.463 回答
0

您必须添加条件签入cellForRowAtIndexPath:才能为之前检查过的任何单元格设置复选标记。保留一组/一组NSIndexPath选定单元格并检查它。

于 2013-07-01T09:49:57.377 回答