I have a UIButton within a custom UITableViewCell. I added this button in Interface Builder.
I then use the following code within cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"GenericCellButton";
GenericCellButton *cell = (GenericCellButton *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = (GenericCellButton *)currentObject;
break;
}
}
}
[cell.inviteButton addTarget:self action:@selector(inviteButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[cell.inviteButton setTag:indexPath.row];
// This statement doesn't get called...?
if ([cell.inviteButton.titleLabel.text isEqualToString:@"Please Wait"]) {
[cell.inviteButton setEnabled:NO];
[cell.inviteButton setTitle:@"Please Wait" forState:UIControlStateDisabled];
}
...
This is the followTapped: method:
- (void)followTapped:(id)sender {
UIButton *button = (UIButton *)sender;
[button setEnabled:NO];
[button setTitle:@"Please Wait" forState:UIControlStateDisabled];
// I then call a service method that then fires off a callback method that refreshes the `tableView`. This changes the button text to "Following".
}
Everything is working just fine in terms of saving the record.
The problem is that before the callback method is fired; if the user scrolls the visible cell out of view before the tableView is refreshed, it’s resetting the button back to “Follow” instead of “Please Wait”, which means if they tap the “Follow” button again it causes issues in my database.
How can I stop that particular cell from refreshing before the tableView is reloaded if it is scrolled out of view? I tried adding some logic in the cellForRowAtIndexPath: that checks for whether the button text is “Please Wait”, but it doesn’t seem to be working as expected. It’s still resetting back to “Follow”.
Now
…