我有一个 UIScrollView,我想在其中包含许多 UITableView,每个都是一个页面。我已将它们添加到我的 ScrollView 中,并验证了 UITableViews 的框架是否设置正确。第一个 UITableView 显示正确,但它不会让我水平滚动以查看其他的。这是我在表格 View 中使用的代码:
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
.
关于iOS:无法在分页 UIScrollView 中的 UITableView 之间滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22544081/