iphone - 如果发生条件,更改 TableView 中新添加的行的背景颜色?

标签 iphone ios ipad

我有一个聊天应用程序,我在其中添加来自 NSMutableArray 的单元格。我正在使用 Pusher api。现在,当用户从 channel 中删除时,我放置了一个 NSNotifications,并且我正在更改 bool 值,根据它的值我正在更改单元格的背景图像。在我的 cellForRowAtIndexpath: 方法中:

if([userid isEqualToString:uidstr])
    {
      if(offline==YES)
        {
         UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"chat_cellreply02.png"]];
            [cell setBackgroundView:img];
            [img release]; 
          }
        else
        {
       UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"chat_cellreply.png"]];
        [cell setBackgroundView:img];
        [img release]; 
        }
    }

它正在工作,但这里的问题是所有单元格的背景都在变化。我只需要更改新添加的单元格的背景。有人可以指导我如何实现这一目标吗?

最佳答案

使您的离线变量属于您在可变数组中保存的结构。然后在 cellForRowAtIndexPath 中检查该变量。

关于iphone - 如果发生条件,更改 TableView 中新添加的行的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14935433/

相关文章:

iphone - 标签栏 Controller 下的导航 Controller 中的数组索引搞砸了

ios - 如何在通知内容扩展中单击按钮时打开两个特定的 View Controller ?

ios - 当我点击返回键时键盘没有退出 (xcode)

ios - 删除KVC生成的NSMutableArray中的NSNull值

ios - 在 iOS 中显示 Powerpoint 演示文稿

iphone - 具有快速 modpow 的 BSD 许可大整数 C 库

iphone - 如何解决 iPhone 中 Twitter 集成中的 "LibXml/xmlreader.h Not found"错误

ios - UITableViewHeader 的 UISearchBar subview ?

iphone - 从 VMWare 在 iPhone/iPad 上启动 Xcode 4.0.2 应用程序

ios - 使用 UITableView 在 iPad 上实现网格...问题