【问题标题】:Use ChildViewControllers in UIScrollview?在 UIScrollview 中使用 ChildViewControllers?
【发布时间】:2012-02-22 12:21:24
【问题描述】:

可以在 UIScrollview 中使用 childViewControllers 吗? 我知道在 ios5 中我们可以使用 childViewControllers 来控制屏幕中的多个视图。

我可以使用 childViewControllers 来控制 uiscrollview 中的每个视图吗? 我想要一个像windows phone 7全景的效果,每个子控制器控制一个页面。 我不知道该怎么做。

还有一个问题:我正在尝试这段代码,但遇到了一个问题。

[self addChildViewController: myTableViewController];
[scrollView addSubview:[[self.childViewControllers objectAtIndex:1] view]];

表格视图可以显示,但是当我触摸行时,它无法推送到详细视图,表格视图委托方法didselected不起作用。

有人可以帮助我吗?非常感谢。

【问题讨论】:

  • 你设置了myTableViewController的delegate属性了吗?

标签: ios uitableview ios5 uiviewcontroller uiscrollview


【解决方案1】:

这些是使它发生的代码:

- (void)configureInfoViewController
{
    TodayViewController *todayVC = [self.storyboard instantiateViewControllerWithIdentifier:@"today"];
    WeekViewController *weekVC = [self.storyboard instantiateViewControllerWithIdentifier:@"week"];
    MonthViewController *monthVC = [self.storyboard instantiateViewControllerWithIdentifier:@"month"];

    [self addChildViewController:todayVC];
    [self addChildViewController:weekVC];
    [self addChildViewController:monthVC];
}

- (void)configureScrollView
{
    [self.scrollView setDirectionalLockEnabled:YES];
    self.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * [self.childViewControllers count], scrollView.frame.size.height);
    for (int i = 0; i < [self.childViewControllers count]; i++) {
        CGRect frame = scrollView.frame;
        frame.origin.x = frame.size.width * i;
        frame.origin.y = 0;
        [[[self.childViewControllers objectAtIndex:i] view] setFrame:frame];
        [scrollView addSubview:[[self.childViewControllers objectAtIndex:i] view]];
    }
}

【讨论】:

    【解决方案2】:

    在这里,您正在使用将子视图控制器添加到 myTableViewController 并尝试从自身访问 childViewController..?

    尝试从 myTableViewController 获取 childViewController,而不是从 self 获取。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-15
      • 2013-04-21
      • 2018-11-13
      • 2018-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多