iOS方式开始向下滚动时,对勾消失
开始向下滚动时,复选标记消失的方式。
下面是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 ; } } }
有什么问题吗 ? 或者如果有其他的技术。
试试这个存储复选标记的单元格数据。希望这可以解决你的问题:
- (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]]; } }
确保将复选标记存储在模型的某处。 随着用户滚动UITableView
单元格将被重新创build。 然后确保在tableView:cellForRowAtIndexPath:
正确地重新设置选中标记。