我有一个UIScrollView,在其中我想包含一些uitableview,每一个是一个页面。我已经将它们添加到我的滚动视图中,并验证了UITableViews的框架设置正确。第一个UITableView显示正确,但它不会让我水平滚动看到其他。下面是我用来查看表视图的代码:
scrollView.delegate=self;
scrollView.scrollEnabled=YES;
tableViews = [[NSMutableArray alloc] initWithCapacity:recipOrgs.count];
for (NSDictionary *orgDict in recipOrgs) {
int index = [recipOrgs indexOfObject:orgDict];
NSLog(@"Creating table view for index: %d",index);
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * index;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
OrganizationTableView *tableView = [[OrganizationTableView alloc] init];
tableView.index=index;
tableView.parentCon=self;
tableView.dataSource=tableView;
tableView.delegate=tableView;
[tableViews addObject:tableView];
[scrollView addSubview:tableView];
[tableView setFrame:frame];
}
知道为什么这不起作用吗?我说过,我检查了UITableView原点的x值,我得到0,320,640等等。
您可能忘记为scrollView
设置contentSize
。
scollView.contentSize = CGSizeMake(recipOrgs * CGRectGetWidth(scrollView.frame), CGRectGetHeight(scrollView.frame));
但是您应该考虑使用UICollectionView
而不是UIScrollView
,然后您可以免费重用逻辑,并且您不必担心contentSize
。