滚动时禁用tableview单元格选中标记

时间:2013-07-01 08:47:01

标签: iphone

当我滚动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);
    }
}

2 个答案:

答案 0 :(得分:0)

您必须在cellForRowAtIndexPath:中添加条件检查,以便为之前检查过的任何单元格设置复选标记。保留所选单元格的NSIndexPath个数组/集,并检查它。

答案 1 :(得分: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;
}