1

开始向下滚动时复选标记消失的方式。

下面是该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 ;
        }
    }
}

有什么问题吗 ?或者如果有任何其他技术。

4

2 回答 2

2

确保将复选标记存储在模型中的某个位置。当用户滚动UITableView. 然后确保在 中正确重新设置复选标记tableView:cellForRowAtIndexPath:

于 2012-07-13T00:00:13.173 回答
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]];
       }
}
于 2014-07-02T06:36:36.440 回答