UITableViewCell button not getting tag when inserting a new row

I created a table view in which we can add and remove rows. Each line has a tagged button that has an indexPath tag. Now when I insert a new row above any row, then the button in that cell gets the correct tag, but the other honeycomb buttons keep the old tag there.

I tried 1. reloading the table - not working 2. reloading the section - not working 3. Reloading lines on all indexPaths - not working

I used the foll code to insert a new row, but the cellForRowAtInsexPath method is only called once, that is, only for the newly added row, due to which the button tag on the old cell remains 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 an infoButton button whose tag is set at the index infoButton.tag = indexPath.row;

+3


source to share


2 answers


If you use the "dequeueReusableCellWithIdentifier:" method when creating your cells, this may be the reason why the button tags are not changing.



0


source


Another reason why tags in table view cells are the wrong way to determine which button was clicked. See my answer here: fooobar.com/questions/146827 / ...



+3


source







All Articles