objective c - Count number of selected rows in uitableview -


what want count number of rows selected after selecting , deselecting row. total count when deselect row want count how many other rows still selected. code follows

//countid = 0; -(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;     }      [self.tableview deselectrowatindexpath:indexpath animated:yes]; } 

and have pass value of countid view , display in button. know small not able it. appreciated.

you can ask table view it's selected indexes, if need how many, can do:

[self.tableview indexpathsforselectedrows].count 

edit:

to keep following cells uitableviewcellaccessorycheckmark can decrement countid so:

if (cell.accessorytype == uitableviewcellaccessorynone) {     cell.accessorytype = uitableviewcellaccessorycheckmark;     countid = countid + 1; }  else {     cell.accessorytype = uitableviewcellaccessorynone;     countid = countid - 1;  } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -