2013-02-18 43 views
0

我有一个聊天应用程序,我在其中添加NSMutableArray中的单元格。我正在使用推送器API。现在,当用户从频道中删除时,我放了一个NSNotifications,并且我正在更改布尔值的值,根据它的值我正在更改单元格的背景图像。在我cellForRowAtIndexpath:梅索德:如果条件发生,更改tableview中新添加的行的背景颜色?

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]; 
     } 
    } 

它的工作,但这里的问题是,所有的细胞都改变背景。我只需要改变新添加的单元格的背景。任何人都可以指导我如何做到这一点?

+0

?行索引单元格>? – 2013-02-18 11:42:55

+0

是的,看到我的编辑 – hacker 2013-02-18 11:45:49

+0

然后我想这个问题是不是与此代码,但在设置离线标志。我猜这个标志对于所有的单元格都是一样的。 – 2013-02-18 11:51:40

回答

1

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

+0

那个窗口只与该用户聊天,所以每个单元格都会被更新。 – hacker 2013-02-18 12:30:59

+0

所以它的信息(不是用户),你的细胞显示? – ilmiacs 2013-02-18 12:33:20

+0

exacltly ............. – hacker 2013-02-18 12:35:27

0

只是检查你的表视图的最后一行,并添加离线设计中有没有像

你去哪里写了这个方法
NSInteger sectionsAmount = [tableView numberOfSections]; 
    NSInteger rowsAmount = [tableView numberOfRowsInSection:[indexPath section]]; 
    if ([indexPath section] == sectionsAmount - 1 && [indexPath row] == rowsAmount - 1) { 
     // This is the last row here do your process 
     } 
+0

这似乎不是一个干净的解决方案,您的问题。它只会影响最后一个单元格。那么如果从频道中删除多个单元格后会发生什么?如果重新连接会发生什么? – ilmiacs 2013-02-18 13:39:04

+0

如果发生重新连接,我正在使用另一个通知重新加载表视图 – hacker 2013-02-18 15:24:07

+0

所以wat ....它会影响最后添加的单元总是。 – hacker 2013-02-18 15:25:04