在UIScrollview的UIView中的UITableView:在UITableView中的数据被清除
为了工作的目的,我需要创建一个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:
我觉得UIPageViewController
会更合适(link)。它看起来像是完成了你想要达到的目标。并且可能比管理嵌入在其他滚动视图中的滚动视图更简单。
UPDATE:
它看起来像你想达到什么样的UIPageViewController
(link)成为可能。如果这能起作用,那将比试图管理嵌入在其他视图中的滚动视图更好。
嵌入UITableView
特别不被Apple推荐。冲突发生时,系统试图找出其中发送事件:
重要:你不应该嵌入 的UIScrollView对象的UIWebView或UITableView的对象。如果这样做,可能会导致意外的行为 ,因为两个对象的触摸事件可能混淆并且错误地处理了 。 (source)
但这里是愚蠢的一部分,当你去到源链接,你会发现,出现在文档的UIWebView
。 苹果忘记把它包含在UITableView
的文档中。
我知道这不是Apple推荐的。 这意味着它可以完成。 – NDakotaBE 2013-02-20 07:04:29
@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
这是一个事实 问题是我需要创建一个viewcontroller,我可以通过动态生成的视图页面,这些视图又有TableViewControllers。由于我必须在表格上面放置额外的数据,因此我不能使用其他任何东西。 有什么想法? – NDakotaBE 2013-02-20 14:58:16
你可以发布你的'UITableViewDataSource'和'UITableViewDelegate'实现的代码吗? – 2013-02-19 15:04:04