ios - UITableViewCellAccessoryCheckmark get vanished after scrolling the tableview -
i'm working on tableview multiple selection, deselect.
i'm having 3 table views (the tableview have tag 400 need multiple selection , deselection -> alllmumbaitableview)
my issue : when i'm selecting multiple rows, uitableviewcellaccessorycheckmark
vanished after scrolling tableview. thing here can see cells still in selected state not showing uitableviewcellaccessorycheckmark
.
after scrolling table looking this
here code
@property (nonatomic, strong) nsmutablearray *arrindexpaths;
uitableview methods -
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *simpletableidentifier = @"simpletableitem"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:simpletableidentifier]; if(tableview.tag == 100) { cell.textlabel.text = [typearray objectatindex:indexpath.row]; } else if (tableview.tag == 300) { cell.textlabel.text = [specialityarray objectatindex:indexpath.row]; } else if (tableview.tag == 400) { if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:simpletableidentifier]; } if ([self.arrindexpaths containsobject:[nsindexset indexsetwithindex:indexpath.row]]) { cell.accessorytype = uitableviewcellaccessorycheckmark; } else { cell.accessorytype = uitableviewcellaccessorynone; } cell.textlabel.text = [allmumbaiarray objectatindex:indexpath.row]; } return cell; } - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { if(tableview.tag == 100) { _typetextfield.text=[typearray objectatindex:indexpath.row]; _typetableview.hidden = yes; } else if (tableview.tag == 300) { _specialitytextield.text=[specialityarray objectatindex:indexpath.row]; _specialitytableview.hidden = yes; } else if (tableview.tag == 400) { uitableviewcell *tableviewcell = [tableview cellforrowatindexpath:indexpath]; tableviewcell.accessorytype = uitableviewcellaccessorycheckmark; [self.arrindexpaths addobject:[nsindexset indexsetwithindex:indexpath.row]]; } } - (void)tableview:(uitableview *)tableview diddeselectrowatindexpath:(nsindexpath *)indexpath { if (tableview.tag == 400) { uitableviewcell *tableviewcell = [tableview cellforrowatindexpath:indexpath]; tableviewcell.accessorytype = uitableviewcellaccessorynone; [self.arrindexpaths removeobject:[nsindexset indexsetwithindex:indexpath.row]]; } }
what want :
1) want uitableviewcellaccessorycheckmark
after scrolling tableview (but should not other rows selected when i'm selecting one. previous problem -> selecting 1 uitableviewcell selects other cell after scrolling )
2) need selected values single array.
i suggest having each different cell identifier. don't know how set tableviews layout looks tableviewcell queue replaces other cells unlike implemented above.
static nsstring *simpletableidentifier = @"simpletableitem"; if(tableview.tag == 100) { simpletableidentifier = @"simpletableitem"; } else if (tableview.tag == 300) { simpletableidentifier = @"simpletableitem1"; } else if (tableview.tag == 400) { simpletableidentifier = @"simpletableitem2"; } uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:simpletableidentifier];
update final
#import "viewcontroller.h" @interface viewcontroller () <uitableviewdatasource, uitableviewdelegate> { nsarray *tmparray; } @property(nonatomic, weak) iboutlet uitableview *tableview1, *tableview2, *tableview3; @end @implementation viewcontroller - (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. tmparray = @[[nsnumber numberwithint:2],[nsnumber numberwithint:3]]; [self.view bringsubviewtofront:self.tableview1]; [self.view bringsubviewtofront:self.tableview2]; [self.view bringsubviewtofront:self.tableview3]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return 20; } - (uitableviewcell*)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *simpletableidentifier = @"simpletableitem"; if (self.tableview1 == tableview) { simpletableidentifier = @"simpletableitem"; } else if (self.tableview2 == tableview) { simpletableidentifier = @"simpletableitem1"; } else if (self.tableview3 == tableview) { simpletableidentifier = @"simpletableitem2"; } uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:simpletableidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:simpletableidentifier]; } if (self.tableview1 == tableview) { cell.textlabel.text = @"tableview1"; } else if (self.tableview2 == tableview) { cell.textlabel.text = @"tableview2"; } else if (self.tableview3 == tableview) { if ([tmparray objectatindex:0] == [nsnumber numberwithint:(int)indexpath.row] || [tmparray objectatindex:1] == [nsnumber numberwithint:(int)indexpath.row] ) { cell.accessorytype = uitableviewcellaccessorycheckmark; } else { cell.accessorytype = uitableviewcellaccessorynone; } cell.textlabel.text = @"tableview3"; } return cell; } - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { return 70; }
Comments
Post a Comment