简体   繁体   中英

Removing UITableViewCell's accessoryView later?

So I'm setting an activity indicator as the accessory view on my table view cells when they are selected.

UITableViewCell *cell = [tableVw cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView *act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[act startAnimating];
[cell setAccessoryView:act];
[act release];

Later on, when I have the data I need to move on, I want to remove this activity indicator before I transition to another view so that the cell returns to it's default state. The following just isn't working.

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:self.tableView.indexPathForSelectedRow];
[cell.accessoryView removeFromSuperview];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];

You should have some sort of way of determining whether or not an object requires an activity indicator in your tableView:cellForRowAtIndexPath: . For example, maintain a dictionary or array that stores whether or not a cell at an index path is still doing something, or create a model object with a property that represents whether or not it's loading, etc.

In your tableView:cellForRowAtIndexPath: , check if the cell at that index path needs an activity indicator view or not, and if it doesn't, set the cell's accessoryView to nil .

Then to remove the accessory view later: [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:theIndexPath] withRowAnimation:UITableViewRowAnimationNone];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM