2012-01-25 39 views
0

我有三個看起來相同的UITableViews。每個放置在UIScrollView的不同子視圖內。當我滾動時,我可以看到每張桌子。第一個表格完美顯示。但是,第二張和第三張表格僅顯示背景顏色。UITableViewCells最初沒有出現

tableView:cellForRowAtIndexPath:爲每個表格的每一行調用,其中我將子視圖插入到單元格的contentView中。在調用這個方法之前,子視圖已經被創建,並且在給定行的三個表中重用(試圖使表看起來相同)。

我做了兩個有趣的發現:

  • ,雖然小區最初不顯示,它會滾動到隱藏的行,然後再次顯示它之後出現。
  • 滾動後單元格出現時,它已從另一個表中移出。它不再出現在它已經顯示的表格中。

這裏是我的代碼:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"PlotCellID"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PlotCell" owner:self options:nil]; 

     if ([nib count] > 0) 
      cell = self.plotCell; 
     else 
      NSLog(@"Failed to load AlertCell nib!"); 
    } 

    // Set up the cell... 
    NSUInteger row = [indexPath row]; 
    AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
    ResultSet *rs = del.resultPlots; 

    CPTGraphHostingView *cellPlotView = [rs.hostingViews objectAtIndex:row]; 
    cellPlotView.frame = cell.contentView.bounds; 

    cellPlotView.autoresizingMask = UIViewAutoresizingFlexibleWidth;  
    [cell.contentView insertSubview:cellPlotView atIndex:0]; 

    return cell; 
} 

cellPlotView是指已經創建的子視圖。

任何想法如何解決這個問題,所以我可以看到我滾動時正確顯示所有表格?就好像單元不能重用內容一樣。謝謝。

+0

三個表視圖使用相同的實現嗎? – 2012-01-25 21:52:41

+0

是的,他們使用相同的實現 – rimsky

+0

查看只能有一個超級視圖。因此創建3個相同的CPTGraphHostingView視圖。 –

回答

0

視圖只能有一個超級視圖。因此創建3個相同的CPTGraphHostingView視圖。