UITableview的渲染问题

UITableview的渲染问题,uitableview,rendering,Uitableview,Rendering,我在iPhone模拟器的导航控制器中遇到了一个非常奇怪的问题。在显示的单元中,只有部分单元正确渲染。它们看起来都是一样的,但大多数都缺少我设置的附件,滚动视图会改变哪个单元格有附件,所以我怀疑这是某种单元格缓存,尽管每个单元格的内容都是正确的。我还设置了一个图像作为背景,它也只是偶尔显示,但我通过更改来修复它 cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yellow-bar_shor

我在iPhone模拟器的导航控制器中遇到了一个非常奇怪的问题。在显示的单元中,只有部分单元正确渲染。它们看起来都是一样的,但大多数都缺少我设置的附件,滚动视图会改变哪个单元格有附件,所以我怀疑这是某种单元格缓存,尽管每个单元格的内容都是正确的。我还设置了一个图像作为背景,它也只是偶尔显示,但我通过更改来修复它

cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yellow-bar_short.png"]];
(它也仅渲染具有背景的随机单元格)以

我现在需要修复附件仅在随机单元格中显示的问题。我试着将代码从CellForRowatinex移动到willDisplayCell,但没有任何区别。我输入了一个log命令,以确认它正在每个帧中运行

基本上,它是一个从服务器获取信息的表视图(UITableViewCellStyleSubtitle),然后通过调用reload的委托方法进行更新。代码是:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSLog(@"%@", [NSString stringWithFormat:@"Setting colours for cell %i", indexPath.row]);

  // Set cell background
  // cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yellow-bar_short.png"]];
  cell.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"yellow-bar_short.png"]];
  cell.textLabel.backgroundColor = [UIColor clearColor];
  cell.detailTextLabel.backgroundColor = [UIColor clearColor];

      // detailTableViewAccessory is a view containing an imageview in this view's nib
      // i.e. nib <- view <- imageview <- image
  cell.accessoryView = detailTableViewAccessory;
}

// Called by data fetching object when done
-(void)listDataTransferComplete:(ArticleListParser *)articleListParserObject
{
  NSLog(@"Data parsed, reloading detail table");
  self.currentTotalResultPages = (((articleListParserObject.currentArticleCount - 1) / 10) + 1);
  self.detailTableDataSource = [articleListParserObject.returnedArray copy]; // make a local copy of the returned array

  // Render table again with returned array data (neither of these 2 fixed it)
  [self.detailTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  // [self.detailTableView reloadData];

  // Re-enable necessary buttons (including table cells)
  letUserSelectRow = TRUE;
  [btnByName setEnabled:TRUE];
  [btnByPrice setEnabled:TRUE];

  // Remove please wait message
  NSLog(@"Removing please wait view");
  [pleaseWaitViewControllerObject.view removeFromSuperview];
}
-(void)tableView:(UITableView*)tableView将显示单元格:(UITableViewCell*)用于rowatindexpath的单元格:(nsindepath*)indepath
{
NSLog(@“%@,[NSString stringWithFormat:@“设置单元格%i的颜色”,indexath.row]);
//设置单元格背景
//cell.backgroundView=[[UIImageView alloc]initWithImage:[UIImageName:@“yellow-bar_short.png”];
cell.backgroundColor=[[UIColor alloc]initWithPatternImage:[UIImage ImageName:@“yellow-bar_short.png”];
cell.textLabel.backgroundColor=[UIColor clearColor];
cell.detailTextLabel.backgroundColor=[UIColor clearColor];
//DetailTableViewAccessority是在该视图的nib中包含imageview的视图

//例如,nib解决了!我认为渲染问题实际上只是我的愚蠢问题(我盲目地遵循教程是正确的)。IB只创建了一个附件视图实例,该实例被分配给一个单元格。通过在每个单元格创建时重新创建视图修复了该问题:

cell.accessoryView = detailTableViewAccessory;
取代

UIImageView *cellAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(308, 0, 12, 75)];
cellAccessoryView.image = [UIImage imageNamed:@"blue-accessory-pointer.png"];
[cell.contentView addSubview:cellAccessoryView];
[cellAccessoryView release];
我还应该补充一点,我对单元格背景的问题是用相同的方法解决的。另外,您可以使用addSubview行来代替addSubview行

cell.accessoryView = cellAccessoryView;

解决了!我认为渲染问题实际上只是我的一个愚蠢问题(因为我盲目地遵循教程)。IB只创建了一个附件视图的实例,该实例被分配给一个单元格。通过在每个单元格创建时重新创建视图修复了该问题:

cell.accessoryView = detailTableViewAccessory;
取代

UIImageView *cellAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(308, 0, 12, 75)];
cellAccessoryView.image = [UIImage imageNamed:@"blue-accessory-pointer.png"];
[cell.contentView addSubview:cellAccessoryView];
[cellAccessoryView release];
我还应该补充一点,我对单元格背景的问题是用相同的方法解决的。另外,您可以使用addSubview行来代替addSubview行

cell.accessoryView = cellAccessoryView;