У меня есть UITableView с несколькими разрешениями, но по какой-то причине, когда я просматриваю UITableView, выбранные мной параметры с UITableViewCellAccessoryCheckmark повторяются при прокрутке.UITableViewCell accessoriesType UITableViewCellAccessoryCheckmark повторяется
Это код, который я использую
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.backgroundColor = [UIColor clearColor];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.textLabel.text = [sortedMachineNames objectAtIndex:indexPath.row];
return cell;
}
#pragma mark - Table view delegate
// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[selectedMachinesMArray addObject:cell.textLabel.text];
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryNone;
NSUInteger index = [selectedMachinesMArray indexOfObject:cell.textLabel.text];
if (index!=NSNotFound) {
[selectedMachinesMArray removeObjectAtIndex:index];
}
}
помощь будет оценена.
«Однако по какой-то причине ...» Причина в том, повторное использование клеток. Сделайте поиск по «отметке галочки», и вы найдете много ответов. – rdelmar