ios - How to limit number of rows selected in uitableview -
i creating tableview want limit number of rows selected 5. if 6th row selected alert appear stating can select 5 rows. can check , uncheck rows minimum 1 row , maximum 5 rows should selected. how can it. current code follows:
-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [self.tableview cellforrowatindexpath:indexpath]; if (cell.accessorytype == uitableviewcellaccessorynone) { cell.accessorytype = uitableviewcellaccessorycheckmark; countid = countid + 1; } else { cell.accessorytype = uitableviewcellaccessorynone; countid--; } // countid = [self.tableview indexpathsforselectedrows].count; [self.tableview deselectrowatindexpath:indexpath animated:yes]; }
where should set limit , how use it? able pass value of countid between 2 view controllers want know how can limit countid between 1 , 5. new appreciated.
-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [self.tableview cellforrowatindexpath:indexpath]; if (cell.accessorytype == uitableviewcellaccessorynone) { if(countid <5) { cell.accessorytype = uitableviewcellaccessorycheckmark; countid = countid + 1; } else { //show alert nslog(@"greater 5"); } } else { if(countid>1) { cell.accessorytype = uitableviewcellaccessorynone; countid--; } else { //show alert nslog(@"must choose 1"); } } // countid = [self.tableview indexpathsforselectedrows].count; [self.tableview deselectrowatindexpath:indexpath animated:yes]; }
it may ful you.., :)
Comments
Post a Comment