在UIScrollview的UIView中的UITableView:在UITableView数据中点击清除

为了工作的目的,我需要创build一个embeddedUIView的UIScrollView,然后通过Xcode中的容器特性embedded一个UITableView。

我的UIScrollView是一个完整的页面滚动查看启用。 我的UIView充满了UIImage,一些UIButton和一个链接到UITableView的容器。

在初始启动时,数据完全加载,这意味着UITableView充满了数据,UIImage被填充,button被正确放置。

但是,对于一些奇怪的原因,当我尝试在容器中的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

我认为一个UIPageViewController会更合适( 链接) 。 它看起来像完成了你想要实现的。 而且可能比pipe理其他滚动视图中embedded的滚动视图更简单。


更新

它看起来像你试图实现UIPageViewController ( 链接 )成为可能。 如果这样工作,那将比试图pipe理其他视图中embedded的滚动视图更好。


embeddedUITableView特别不被Apple推荐。 当系统试图找出发送事件的位置时,会出现冲突:

重要说明 :您不应该在UIS​​crollView对象中embeddedUIWebView或UITableView对象。 如果这样做,可能会导致意外的行为,因为两个对象的触摸事件可能会混淆并被错误地处理。 ( 来源 )

但是这里是愚蠢的部分,当你去源链接,你会注意到出现在UIWebView的文档。 苹果忘了把它包含在 UITableView 的文档中