用UITableview渲染问题

时间:2010-05-17 08:15:18

标签: uitableview rendering

我在iPhone模拟器上的导航控制器中有一个非常奇怪的UITableview问题。在显示的单元格中,只有一些正确呈现。它们都应该看起来一样,但是大多数都缺少我设置的附件,滚动视图更改哪个单元格具有附件,所以我怀疑它是某种单元格缓存发生,尽管每个单元格的内容都是正确的。我还设置了一个图像作为背景,也只是偶尔显示,但我通过更改

来修复它
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yellow-bar_short.png"]];

(也只是将具有背景的随机单元格渲染到

cell.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"yellow-bar_short.png"]];

我现在需要通过仅在随机单元格上显示的附件来解决问题。我尝试将代码从cellForRowAtIndex移动到willDisplayCell,但它没有任何区别。我输入了一个日志命令来确认它正在运行每一帧。

基本上它是一个表视图(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];
}

我只包含了我认为相关的代码,如果需要可以提供更多代码。我无法在iPhone上测试它,所以我不知道它是否只是模拟器异常或我的代码中的错误。我总是从问题,任何想法中得到很好的反馈?

1 个答案:

答案 0 :(得分:1)

解决!我认为渲染问题实际上只是我的愚蠢问题(盲目跟随教程是正确的)。 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行
cell.accessoryView = cellAccessoryView;