Question

I'm experiencing this strange situation. I have a UITableView where, when the user selects a cell, a long (network) process begins. So, I performed this in a background thread and I placed (in the didSelectRowAtIndexPath) a UIActivityIndicatorView as the accessory view. This is what I wrote:

UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView* activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
cell.accessoryView = activityView;
[activityView startAnimating];
[activityView release];

everything seems to work correctly, except that, if during a loading process (when the indicator is animated), I switch the view using a UITabBar, when I go back to the UITableView, the UIActivityIndicatorView that should still be there has disappeared. Any idea of what I did wrong? Thanks!

Was it helpful?

Solution

I was looking back at this issue, and... after reading the question now, I'm laughing :-) Answer to my own question is: nothing is wrong with the code, it works very well... but making the UIActivityIndicatorView white... makes it difficult to see it on white background :-D :-D The posted code is correct.

OTHER TIPS

When you go back to the table view after going to another tab, cellForRowAtIndexPath: messages are sent to the table view controller to display the cells of the table but the activity indicator view was set as the accessory view of the cell in the didSelectRowAtIndexPath: method. So, essentially, you changed the cell (i.e., displayed the activity indicator view) when the cell was selected but when you left the view and came back the cellForRowAtIndexPath: method was used to re-display the cell (and, hence, no activity indicator view).

You'll have to keep track of what cells currently have activity indicator views and make sure you set the accessory view of those cells with a UIActivityIndicatorView in the cellForRowAtIndexPath: method. Obviously, if the activity associated with a cell has completed then don't display the activity indicator view for that cell so you'll have to keep track of whether the activities have completed yet or not. There are many ways you can do this so you'll have to decide what works best for your situation.

It's not true that cellForRowAtIndexPath: messages are sent (at least necessarily) when returning to the table view from another tab view so I've "deleted" my answer above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top