iphone - all tableCells in different sections got selected of same row (using NSIndexPath) -


i tried create simple checklist style tableview following:

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     if ([_selectedrows containsobject:indexpath]) {         [_selectedrows removeobject:indexpath];         [tableview cellforrowatindexpath:indexpath].accessorytype = uitableviewcellaccessorynone;     } else {         [_selectedrows addobject:indexpath];         [tableview cellforrowatindexpath:indexpath].accessorytype = uitableviewcellaccessorycheckmark;     }     [tableview deselectrowatindexpath:indexpath animated:yes]; } 

however, when select first item , scroll, found out first items in same section has checkmark besides it. doesn't nsindexpath contain both row , section? made items got selected here? :(

thanks!


- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cell_identifier];  if (!cell) {     cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cell_identifier]; }  if ([_selectedrows containsobject: indexpath]) {     cell.accessorytype = uitableviewcellaccessorycheckmark; }  abrecordref selectedfriend = cfarraygetvalueatindex(_allfriends, [indexpath row]); nsstring *firstname = (__bridge nsstring *)(abrecordcopyvalue(selectedfriend, kabpersonfirstnameproperty)); nsstring *lastname = (__bridge nsstring *)(abrecordcopyvalue(selectedfriend, kabpersonlastnameproperty)); cell.textlabel.text = [nsstring stringwithformat:@"%@ %@", firstname, lastname];  return cell; 

}

because of cell reusage, have remove checkmark accessory if necessary (in cellforrowatindexpath):

if ([_selectedrows containsobject: indexpath]) {     cell.accessorytype = uitableviewcellaccessorycheckmark; } else {     cell.accessorytype = uitableviewcellaccessorynone; } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -