I’m getting a weird issue. I have a custom UITableViewCell and each cell has a UIButton and UITextField. When the button is clicked, it changes the textfield value to some constant.
Now in the cellForRowAtIndexPath method I have this:
folderTitleTextView.tag=indexPath.row;
[arrayOfTextFields insertObject:folderTitleTextView atIndex:indexPath.row];
NSLog(@"indexpath.row:%i", indexPath.row);
NSLog(@"text fields count %i", [arrayOfTextFields count]);
So if I have two cells, then every time I reload the table, it adds two more objects to the arrayofTextFields, even though it should replace the existing ones. So if I have two cells and I reload the table 3 times, then for some reason arrayOfTextFields count is 8.
This
folderTitleTextView.tag=indexPath.row;is not a good idea because everything starts with a tag of0, so when accessing views withviewWithTag:0or when setting up the row0, you will get weird results.I would suggest also checking the number of items in
arrayOfTextFieldsand use[arrayOfTextFields replaceObjectAtIndex:indexPath.row withObject:folderTitleTextView];or[arrayOfTextFields insertObject:folderTitleTextView atIndex:indexPath.row];depending on the current count forarrayOfTextFieldsTry this: