我有一个应用程序,当用户选择每一行时,我会更改单元格背景图像。就像这样`
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
for (int i = 0; i < [tableView numberOfRowsInSection:0]; i++) {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
cell.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:@"white_cell.png"]];
}
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:@"white_cell_check.png"]];
if (indexPath != nil) {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
`它工作正常。我的问题是当我弹回到前一个 View 时的详细 View ,即到 TableView Controller 时, TableView 中更改后的背景图像保持不变。但我需要它是正常的.有人可以帮助我吗?
最佳答案
只需在 Controller 重新出现时重新加载表格,它就会重新加载数据,并且 didSelectRowAtIndexPath
不会被调用,因此您的单元格将具有初始背景。
- (void)viewWillAppear:(animated){
[super viewWillAppear:animated];
[instanceToYourTableView reloadData];
}
关于iphone - 弹出回 View Controller 时如何更改单元格的背景图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14536282/