Uitableview 从详细信息视图返回时,从单元格内容视图中删除UIActivityIndicator

Uitableview 从详细信息视图返回时,从单元格内容视图中删除UIActivityIndicator,uitableview,uiactivityindicatorview,Uitableview,Uiactivityindicatorview,我有一个UITableView,它可以在单击单元格时从internet获取数据。它显示UIActivity指示器,然后推送到详细视图控制器。单击“上一步”时,单击的UITableView单元格背景为灰色,单元格内容不再存在 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath - (void)viewWillAppear:(BOOL)animated { [

我有一个UITableView,它可以在单击单元格时从internet获取数据。它显示UIActivity指示器,然后推送到详细视图控制器。单击“上一步”时,单击的UITableView单元格背景为灰色,单元格内容不再存在

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (void)viewWillAppear:(BOOL)animated {


[  _activityIndicatorCell stopAnimating];
[  _activityIndicatorCell hidesWhenStopped];

[self retrieveData];
}
{ 静态NSString*CellIdentifier=@TableCell; TabelCell*cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]

_activityIndicatorCell = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

// Get center of cell (vertically)
int center = [cell frame].size.height / 2;

int width = [cell frame].size.width / 1.1;

// Locate spinner in the center of the cell at end of text
[ _activityIndicatorCell  setFrame:CGRectMake(width ,center - 9, 16, 16)];

[_activityIndicatorCell setHidden:YES];
[[cell contentView] addSubview:_activityIndicatorCell];


[  _activityIndicatorCell startAnimating];


[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}

然后我添加了这段代码以删除UIActivityIndicator,但它在我单击的单元格周围仍然有一个灰色框,并且我的UILabel内容不再存在

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (void)viewWillAppear:(BOOL)animated {


[  _activityIndicatorCell stopAnimating];
[  _activityIndicatorCell hidesWhenStopped];

[self retrieveData];
}
我还将在retrieveData方法中重新加载tableview

你知道为什么这样不行吗

如果我从numberOfRowsInSection方法中添加单元格数据,它可以工作,但这是否正确

此外,单元格仍为灰色,即使我运行以下命令,也不会取消选择:

[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];

将此添加到did select方法解决了问题:

[cell setSelected:NO animated:YES];