UITableViewCell和UITableView重复选择其他单元格?

Bas*_*ous 2 iphone objective-c uitableview

我在UITableView中工作并尝试让用户使用此代码选择单元格

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger row = [indexPath row];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if(cell != nil)
    {
        if(cell.accessoryType == UITableViewCellAccessoryNone)
        {
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        }
        else
        {
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但问题是当单元格数超过一页时,如果选择单元格编号1,则每个页面中的行编号1也将被选中.

iPr*_*mer 8

static NSString * cellIdentifier = @"CellIdentifier" 
Run Code Online (Sandbox Code Playgroud)

在这个地方使用

NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%i",indexPath.row];
Run Code Online (Sandbox Code Playgroud)


Ala*_*ter 5

很好的回答,你真的帮助我走上正轨.

我2美分帮助别人:

我正在使用分组表,所以我将其更改为:

NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%i-%i", indexPath.section, indexPath.row];
Run Code Online (Sandbox Code Playgroud)

希望这有助于其他人.