iOS:无法在分页 UIScrollView 中的 UITableView 之间滚动

标签 ios objective-c cocoa-touch uitableview uiscrollview

我有一个 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/

相关文章:

ios - iOS 设备未收到 Urban Airship iOS 推送通知

ios - 在 react-native 中打开键盘时,ScrollView 无法滚动到底部。 [IOS]

ios - 按下回车键时如何在多个文本字段输入中切换?

ios - 推荐?新类(xib)或类中的新 View

ios - 约束两个 View 以用视觉格式填充屏幕时忽略第二个 View 的大小

iphone - 为 UITableViewCell 的飞行设置动画

ios - 为什么我每次需要使用它时都必须实例化 appdelegate?

ios - 不兼容的 CoreData 存储是否总是会导致崩溃?

cocoa - Xcode 断点 [NSExceptionRaise] 与 -[NSExceptionRaise]

ios - 选择 UITableView 中的行时如何清除文本字段?