iosobjective-cuiactivityindicatorview

UIActivityIndicator disappears


I have tableView with rows. If I click on row UIActivityIndicator start animating. But if I scroll tableView indicator disappears. How to fix it?

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.frame = CGRectMake(0, 0, 24, 24);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryView = spinner;
[spinner startAnimating];

Solution

  • It happens because your cell reuse while scrolling. You need to save state for animating of UIActivityIndicator in your model and reload needed cell by index.