Iphone IOS tableview:在滚动完成之前不会显示拉伸图像

Iphone IOS tableview:在滚动完成之前不会显示拉伸图像,iphone,ios,objective-c,uitableview,Iphone,Ios,Objective C,Uitableview,我想在我的项目中创建聊天泡泡视图。我把图像拉伸成泡沫。 但是问题发生了,如果我滚动单元格使其不可见,在单元格回到原始位置后,图像可以拉伸,这是显示拉伸图像的唯一方法 以下图像是有关此问题的简要说明 故事板UIImageView中的气泡视图布局是拉伸图像: 滚动前: 滚动后: 最初显示气泡视图时(其原始显示方法:导航栏项Segue),并在viewWillExample()中调用拉伸函数时,将显示拉伸法线 以下是关键代码: 单元中气泡的初始拉伸: - (UITableViewCell *)ta

我想在我的项目中创建聊天泡泡视图。我把图像拉伸成泡沫。 但是问题发生了,如果我滚动单元格使其不可见,在单元格回到原始位置后,图像可以拉伸,这是显示拉伸图像的唯一方法

以下图像是有关此问题的简要说明

故事板UIImageView中的气泡视图布局是拉伸图像:

滚动前:

滚动后:

最初显示气泡视图时(其原始显示方法:导航栏项Segue),并在viewWillExample()中调用拉伸函数时,将显示拉伸法线

以下是关键代码: 单元中气泡的初始拉伸:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
   NSString *cellID = @"chatCell";
    UIBubbleTableViewCell *cell = (UIBubbleTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellID];
   //CAll stretch function
   cell.dataInternal = dataInternal;
}
拉伸功能:

bubbleImage.image = [[UIImage imageNamed:@"chat2.png"] stretchableImageWithLeftCapWidth:21 topCapHeight:14];
bubbleImage.frame = CGRectMake(40, 10, 267, 105);
每更新一次调用拉伸函数:

- (void)viewDidAppear:(BOOL)animated{
[chatTable reloadData];
}

无论如何,只有滚动结束,图像才能显示。我调试项目,并记录拉伸数据,一切都很好


感谢您的建议,我如何解决此问题。

您要做的是将图像拉伸功能置于

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

委托方法。只有在这一点上,您才能知道要显示的表格单元格的实际大小。然后,您可以将气泡图像拉伸到心满意足的程度。

我尝试了您的方法,将拉伸功能移动到willDisplayCell,同样的问题也发生了。我遗漏了什么吗?把你的完整代码贴出来,让我看看。看到您的拉伸代码仅在滚动时被调用,您缺少了一些内容。-(void)tableView:(UITableView)tableView将显示单元格:(UITableViewCell*)用于RowAtIndexPath的单元格:(NSIndexPath*)indexPath{UIBubbleTableViewCell*Ccell=(UIBubbleTableViewCell)单元格;Ccell.bubbleImage=[[UIImage ImageName:@“chat2.png”]StretcableImageWithLeftCapWidth:25 topCapHeight:14];Ccell.bubbleImage.frame=CGRectMake(40,40,197+30,90+15);NSLog(@“来宾bubbleImage.image结构:%f,%f”,cell.bubbleImage.center.x,cell.bubbleImage.center.y);这是我的拉伸代码,请检查。谢谢!!在willDisplayCell中移动拉伸代码,结果相同,只需将tableview滚动到顶部(单元格更新),图像即可正常拉伸。