, поэтому у меня есть много ячеек в моем UITableView и при прикосновении к ячейке, дополнительные ячейки, которые только что вне поля зрения, также имеют тики. Я считаю, что это происходит потому, что клетки повторного использования или что-то из-за dequeueReusableCellWithIdentifier:
Проблема с множественным UITableViewCellAccessoryCheckmark, применяемым на одном касании UITableCell
Heres мой код:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone){
[addPapersSelectedRowsArray addObject:[NSNumber numberWithInt:indexPath.row]];
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
}
else if (cell.accessoryType == UITableViewCellAccessoryCheckmark){
cell.accessoryType = UITableViewCellAccessoryNone;
[addPapersSelectedRowsArray removeObject:[NSNumber numberWithInt:indexPath.row]];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *currentPapersSecltion = [papersDataDictionary objectAtIndex:indexPath.row];
[[cell textLabel] setText:[currentPapersSecltion objectForKey:@"Title"]];
return cell;
}
Также вытягивать данные из .plist в viewDidLoad
:
//Load papers data from the local plist
papersDataDictionary = [[[NSDictionary alloc] initWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"papers.plist"]] objectForKey:@"Rows"];
Кто-нибудь знает как это исправить? Спасибо, ребята!
Dex
Почтовый код для вашего метода cellForRowAtIndexPath datasource – 0x8badf00d
@ 0x8badf00d добавлен! – DexCurl
Где находится ваш cell.accessoryType = UITableViewCellAccessoryNone; в методе cellForRowAtIndexPath? и вносить изменения в ваш метод делегата в соответствии с ответом @samfisher. – 0x8badf00d