Objective c willDisplayCell上的UITableViewCell更新图像
我正在尝试在插入最后一行相同类型的数据之后更新tableview的最后一行。我想要的是更改我放在xib中的自定义uiimageview中的图像。 我通过在插入之后调用[_tableviewreloaddata]实现了这一特性,但这样插入动画就消失了,性能变得更差 以下是我编写的部分代码: •在代表中:Objective c willDisplayCell上的UITableViewCell更新图像,objective-c,uitableview,ios7,uiimageview,Objective C,Uitableview,Ios7,Uiimageview,我正在尝试在插入最后一行相同类型的数据之后更新tableview的最后一行。我想要的是更改我放在xib中的自定义uiimageview中的图像。 我通过在插入之后调用[_tableviewreloaddata]实现了这一特性,但这样插入动画就消失了,性能变得更差 以下是我编写的部分代码: •在代表中: -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPat
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
[_dataSource setIsRead:(BOOL)read AtIndexPath:indexPath];
[_dataSource configureCell:(WMChatTableViewCell *)cell AtIndexPath:indexPath];
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
[cell setNeedsLayout];
[cell layoutIfNeeded];
}
•在数据源中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
WMMessage *message = [self messageAtIndexPath:indexPath];
/**
Message sent by the user
*/
if ([message.sender_id intValue] == [[[NSUserDefaults standardUserDefaults]valueForKey:kUserIdKey]intValue]) {
WMRightChatTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:rightTextIdentifier];
if (cell == nil) {
cell = [[WMRightChatTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:rightTextIdentifier];
}
[self configureCell:cell AtIndexPath:indexPath];
return cell;
}
/**
Message sent by the recipient
*/
else{
WMLeftChatTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:leftTextIdentifier];
if (cell == nil) {
cell = [[WMLeftChatTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:leftTextIdentifier];
}
[self configureCell:cell AtIndexPath:indexPath];
return cell;
}
return nil;
}
-(void)configureCell:(WMChatTableViewCell *)cell AtIndexPath:(NSIndexPath *)indexPath{
WMMessage *message = [self messageAtIndexPath:indexPath];
....
/**
Last message sent by the recipient
*/
if (!([message.sender_id intValue] == [[[NSUserDefaults standardUserDefaults]valueForKey:kUserIdKey]intValue]) &&
[message isEqual:[[_messagesMatrix lastObject]lastObject]]) {
/**
An highlighted version of the background.
Normally the left cell has the "BoxChat_sx" image, only when it's the last one, the image should change
*/
[cell.balloonImageView setImage:[UIImage imageNamed:@"BoxChat_sx_new"]];
....
}
else if(!([message.sender_id intValue] == [[[NSUserDefaults standardUserDefaults]valueForKey:kUserIdKey]intValue])){
/*
If it's not the last anymore, the image should change back to it's original state
*/
[cell.balloonImageView setImage:[UIImage imageNamed:@"BoxChat_sx"]];
...
}
}
如果不调用[\u tableView reloadData],此代码将不会更新imageView。有没有一种方法可以在不调用重载数据或至少保持插入动画的情况下实现此功能