iphone - 弹出回 View Controller 时如何更改单元格的背景图像?

标签 iphone ios ipad

我有一个应用程序,当用户选择每一行时,我会更改单元格背景图像。就像这样`

- (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/

相关文章:

java - 现有应用程序(java/eclipse/android)到其他平台

iphone - 如何在 iPhone 的自定义导航栏中创建导航栏项目?

javascript - Cordova 闹钟

javascript - 在解决 iOS 13 错误时检测何时启动 iOS Webclip

iphone - iOS - 调整 UILabel 大小以匹配内容?

iphone - 找到最接近给定点的点

ios - 核心数据 : Add relation object to existing object

ios - 使用 Swift 3 获取 iPhone 或 iPad 设备的 IP 地址

iphone - UIbutton 宽度和高度为零?

JavaScript 拖放不适用于 iPad