iOS方式开始向下滚动时,Checkmark消失

时间:2012-07-12 23:54:48

标签: ios uitableview

勾选标记在开始向下滚动时消失。

下面是didSelectRowAtIndexPath方法的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

    if (selectedCell.accessoryType == UITableViewCellAccessoryCheckmark) {
        selectedCell.accessoryType = UITableViewCellAccessoryNone;

        if ([[[collectionDataArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"creditHours"]==@"1") {
            totalHoure = totalHoure - 1;
        }

    } else {

        selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;

        if ([[[collectionDataArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"creditHours"]==@"1") {
            totalHoure = totalHoure + 1 ;
        }
    }
}

有什么问题吗?或者是否有其他技术。

2 个答案:

答案 0 :(得分:2)

确保在某个地方存储模型中的复选标记。当用户滚动UITableView时,将动态重新创建单元格。然后确保在tableView:cellForRowAtIndexPath:

中正确地重新设置复选标记

答案 1 :(得分:1)

尝试使用此选项来存储复选标记单元格数据。希望这可以解决您的问题:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
       UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

       if ([selectedCell accessoryType] == UITableViewCellAccessoryNone || [selectedCell accessoryType]== UITableViewCellAccessoryDisclosureIndicator)   
       {
           [selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark];
                    [Mybuffer addObject:[arrItem objectAtIndex:indexPath.row]];
       }
       else
       {
           [selectedCell setAccessoryType:UITableViewCellAccessoryNone];
           [Mybuffer removeObject:[NSNumber numberWithInt:indexPath.row]];
       }
}