2013-02-19 102 views
1

爲了工作的目的,我需要創建一個UIScrollView,它嵌入了一個UIView,然後通過Xcode中的容器特性嵌入一個UITableView。在UIScrollview的UIView中的UITableView:在UITableView中的數據被清除

我的UIScrollView是一個完整的頁面滾動查看啓用分頁。 我的UIView充滿了UIImage,一些UIButton和一個鏈接到UITableView的容器。

在初次啓動時,數據完全加載,這意味着UITableView充滿了數據,UIImage被填充以及按鈕被正確放置。

但是,對於一些奇怪的原因,當我嘗試在容器中的UITableView中點擊或滾動時,我的UITableView中的所有數據都被清除。

我在這裏發佈這個問題,因爲我還沒有在StackOverFlow或任何其他網站上發現任何其他類似問題。

UITableViewCode:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self.productTable setBackgroundView:nil]; 
    self.productTable.backgroundColor = [UIColor clearColor]; 
    self.productTable.delegate = self; 
    self.productTable.dataSource = self; 
} 

- (void) viewDidAppear:(BOOL)animated { 
    /*CGSize tmp = self.productTable.contentSize; 
    self.productTable.frame = CGRectMake(0, 0, tmp.width, tmp.height * 3);*/ 


} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 

    // Return the number of sections. 
    NSLog(@"section count : %i", [self.Products count]); 
    return [self.Products count]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    xcsSectionInfo *sectionInfo = [self.Products objectAtIndex:section]; 
    if (sectionInfo.isOpen == NO) { 
     return 1; 
    } else { 
     return 3; 
    } 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    xcsSectionInfo *sectionInfo = [self.Products objectAtIndex:indexPath.section]; 

    if (indexPath.row == 0) { 
     static NSString *CellIdentifier = @"Header"; 
     xcsProductHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
     cell.articleNumber.text = sectionInfo.product.articleNumber; 
     cell.articleColor.text = sectionInfo.product.articleColor; 
     cell.backgroundColor = [UIColor grayColor]; 
     if (sectionInfo.isOpen == YES && sectionInfo == self.currentSectionInfo) { 
      cell.expandImage.image = [UIImage imageNamed:@"arrow_down.png"]; 
     } else if (sectionInfo.isOpen == NO) { 
      cell.expandImage.image = [UIImage imageNamed:@"arrow_up.png"]; 
     } 
     return cell; 
    } else if (indexPath.row == 1) { 
     static NSString *CellIdentifier = @"ProductHeader"; 
     xcsProductTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
     cell.colorTempHeader.text = @"Color Temperature"; 
     cell.sourceQualityHeader.text = @"Source Quality"; 
     cell.sourceTypeHeader.text = @"Source Type"; 
     cell.luminaireFluxHeader.text = @"Luminaire Flux"; 
     cell.powerConsumptionHeader.text = @"Power Consumption"; 
     cell.luminaireEfficacyHeader.text = @"Luminaire Efficacy"; 
     cell.backgroundColor = [UIColor grayColor]; 
     return cell; 
    } else if (indexPath.row == 2) { 

     static NSString *CellIdentifier = @"Product"; 
     xcsProductCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
     cell.colorTemp.text = sectionInfo.product.colorTemperature; 
     cell.sourceQuality.text = sectionInfo.product.sourceQuality; 
     cell.sourceType.text = sectionInfo.product.sourceType; 
     cell.luminaireFlux.text = sectionInfo.product.luminaireFlux; 
     cell.powerConsumption.text = sectionInfo.product.powerConsumption; 
     cell.luminaireEfficacy.text = sectionInfo.product.luminaireEfficacy; 
     cell.backgroundColor = [UIColor grayColor]; 
     return cell; 
    } 
} 

#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
     xcsSectionInfo *sectionInfo = [self.Products objectAtIndex:indexPath.section]; 
    NSIndexPath *path0 = [NSIndexPath indexPathForRow:[indexPath row]+1 inSection:[indexPath section]]; 
    NSIndexPath *path1 = [NSIndexPath indexPathForRow:[indexPath row]+2 inSection:[indexPath section]]; 
      NSArray *indexPathArray = [NSArray arrayWithObjects: path0, path1, nil]; 
    if (sectionInfo.isOpen == NO) { 
     sectionInfo.isOpen = YES; 
     [tableView insertRowsAtIndexPaths:indexPathArray withRowAnimation:NO]; 
    } else { 
     sectionInfo.isOpen = NO; 
     [tableView deleteRowsAtIndexPaths:indexPathArray withRowAnimation:NO]; 
    } 
    [self.Products replaceObjectAtIndex:indexPath.section withObject:sectionInfo]; 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    self.currentSectionInfo = sectionInfo; 
    [tableView reloadData]; 
} 

順便說一句:我使用的是故事板

的問候和感謝提前。

+2

你可以發佈你的'UITableViewDataSource'和'UITableViewDelegate'實現的代碼嗎? – 2013-02-19 15:04:04

回答

2

更新2

我覺得UIPageViewController會更合適(link‌​)。它看起來像是完成了你想要達到的目標。並且可能比管理嵌入在其他滾動視圖中的滾動視圖更簡單。


UPDATE

它看起來像你想達到什麼樣的UIPageViewControllerlink)成爲可能。如果這能起作用,那將比試圖管理嵌入在其他視圖中的滾動視圖更好。


嵌入UITableView特別不被Apple推薦。衝突發生時,系統試圖找出其中發送事件:

重要:你不應該嵌入 的UIScrollView對象的UIWebView或UITableView的對象。如果這樣做,可能會導致意外的行爲 ,因爲兩個對象的觸摸事件可能混淆並且錯誤地處理了 。 (source

但這裏是愚蠢的一部分,當你去到源鏈接,你會發現,出現在文檔的UIWebView蘋果忘記把它包含在UITableView的文檔中。

+0

我知道這不是Apple推薦的。 這意味着它可以完成。 – NDakotaBE 2013-02-20 07:04:29

+0

@NDakotaBE它可以,但它往往比它的價值更麻煩(你可以篩選[這些](https://www.google.ca/#hl=en&output=search&sclient=psy-ab&q=Embedding+UITableView+ + A +的UIScrollView&OQ =嵌入&gs_l = hp.3.0.35i39j0l3.5018.6278.0.9790.9.9.0.0.0.0.182.1128.1j8.9.0.les%3B..0.0 ... 1c.1.4.psy-ab.EkMFnyYhtK8&PBX = 1&BAV內部= on.2,or.r_gc.r_pw.r_cp.r_qf。&bvm = bv.42661473,d.dmQ&fp = eb9fa80f02048b55&biw = 1352&bih = 841)posts如果你喜歡,但我們不能控制內部發生的任何類,所以在你周圍發現的東西可能會在未來發生破裂 – 2013-02-20 14:31:46

+0

這是一個事實 問題是我需要創建一個viewcontroller,我可以通過動態生成的視圖頁面,這些視圖又有TableViewControllers。由於我必須在表格上面放置額外的數據,因此我不能使用其他任何東西。 有什麼想法? – NDakotaBE 2013-02-20 14:58:16