4

i have created a tableview in which we can add and delete rows. On each row there is a button having tag as that of the indexPath. Now when i insert a new row above any row then that the button in that cell gets the correct tag, but the other cell-buttons retains there old tag.

I tried 1. reloading the tableview - not working 2. reloading the section - not working 3. reloading rows at all the indexPaths - not working

I used foll code to insert the new row but the cellForRowAtInsexPath method gets called only once, i.e only for the newly added row, due to which the tag of the button on old cell is remaining the same

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:newRowNo inSection:0];
NSArray *otherArray = [NSArray arrayWithObject:indexPath];
[tableViewObj insertRowsAtIndexPaths:otherArray withRowAnimation:UITableViewRowAnimationNone];

and in cellForRowAtIndexPath:(NSIndexPath *)indexPath i have a button infoButton whose tag is set a per the indexPath infoButton.tag = indexPath.row;

anshuman
  • 131
  • 2
  • 7
  • Post some code please, everything else is just guesswork. – Alexander Mar 07 '12 at 10:24
  • 3
    Yet another reason why tags in your table view cells are the wrong way to work out what button has been pressed. See my answer here: http://stackoverflow.com/a/9274863/852828 – jrturton Mar 07 '12 at 10:42
  • @jrturton consider making your comment an answer! – QED Mar 07 '12 at 10:49
  • @psoft if you insist, didn't want to get undeserved rep from it but it would allow this question to be closed. – jrturton Mar 07 '12 at 11:04
  • Look at my suggestion to a similar question: http://stackoverflow.com/a/9579794/5049 . tl;dr - avoid the tagging method. – macbirdie Mar 07 '12 at 11:11
  • IMO the rep is deserved as you knew the answer (well, *an* answer). Of course, I'm sometimes skeptical that new users will accept... oh well, I learned something anyway. – QED Mar 07 '12 at 11:11
  • 1
    @macbirdie glad I'm not the only anti-tagger out there! Your solution is good too, +1. – jrturton Mar 07 '12 at 11:24

2 Answers2

3

Yet another reason why tags in your table view cells are the wrong way to work out what button has been pressed. See my answer here: https://stackoverflow.com/a/9274863/852828

Community
  • 1
  • 1
jrturton
  • 118,105
  • 32
  • 252
  • 268
1

If you are using the method "dequeueReusableCellWithIdentifier:" when creating your cells, that might be the reason why the button tags do not change.

flavianatill
  • 484
  • 3
  • 9