简体   繁体   English

稍后删除UITableViewCell的annexView吗?

[英]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: . 您应该以某种方式确定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 . 在您tableView:cellForRowAtIndexPath:检查,如果该索引路径细胞需要一个活动的指标视图或没有,如果没有,细胞的设置accessoryViewnil

Then to remove the accessory view later: [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:theIndexPath] withRowAnimation:UITableViewRowAnimationNone]; 然后,稍后删除附件视图: [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:theIndexPath] withRowAnimation:UITableViewRowAnimationNone];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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