您应该首先将所有视图控制器添加到数组中:
_viewControllers = [[NSMutableArray alloc] init];
[_viewControllers addObject:hoofdstukController];
[_viewControllers addObject:hoofdstukController0];
[_viewControllers addObject:hoofdstukController1];
//etc.
然后你可以遍历该数组并将它们的视图添加为子视图。请注意,您还应该将它们添加为父视图控制器的子视图控制器:
编辑:对不起'我'工作你需要修改一下
for (UIViewController *vc in _viewControllers)
{
CGRect frame = _scrollView.frame;
frame.origin.x = frame.size.width * i;
frame.origin.y = 0;
vc.view.frame = frame;
[viewControllerHostingTheScrollView addChildViewController:vc];
[_scrollView addSubview:vc.view];
[vc didMoveToParentViewController:viewControllerHostingTheScrollView];
}
编辑:对不起'我'工作你需要修改一下:
int i = 0;
for (UIViewController *vc in _viewControllers)
{
CGRect frame = _scrollView.frame;
frame.origin.x = frame.size.width * i++;
frame.origin.y = 0;
vc.view.frame = frame;
[viewControllerHostingTheScrollView addChildViewController:vc];
[_scrollView addSubview:vc.view];
[vc didMoveToParentViewController:viewControllerHostingTheScrollView];
}