Try this:
- (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];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(270, 15, 17, 17)];
imageView.tag = CELL_IMGVIEW_TG;
[cell.contentView addSubview:imageView];
}
UIImageView* pImgView = (UIImageView*)[cell.contentView viewWithTag:CELL_IMGVIEW_TG];
if (self.prevRowIndex == indexPath.row) {
pImgView.image = [UIImage imageNamed:@"btn_checkmark_on.png"];
}
else{
pImgView.image = [UIImage imageNamed:@"btn_checkmark_off.png"];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.prevRowIndex = indexPath.row;
[self.tableView reloadData];
}
And you'd better replace prevRowIndex
with selectedRowIndex
which will be clear for understanding.