2010-05-17 129 views
1

我在iPhone模拟器上的导航控制器中有一个非常奇怪的问题与UITableview。在显示的单元格中,只有一些单元被正确渲染。他们都应该看起来一样,但大多数都缺少我设置的附件,滚动视图变化的细胞有附件,所以我怀疑它是某种细胞缓存发生,虽然内容是正确的每个细胞。我还设置一个图像作为背景,并且也仅显示零星但我固定,通过改变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

已解决!我认为渲染问题实际上只是我的一个愚蠢问题(盲目跟随教程服务我)。 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]; 

我还要补充一点,我曾与单元格背景的问题是固定的同样的方法。此外,您可以使用

cell.accessoryView = cellAccessoryView; 
代替addSubview行