UITableViewCell and UITableView Repeat the selection on other cells?

advertisements

I am working in UITableView and trying to let the user to select cells using this code

- (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;
        }
    }
}

but the problem is when the cell count over one page if you select cell number 1 the row number 1 in each page will be selected too.


static NSString * cellIdentifier = @"CellIdentifier"

in this place use

NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%i",indexPath.row];