Reputation: 2294
i have one scrollview and 4 UIviewcontrollers with xib files now i want to add 4 viewcontrollers to scrollview
and also the scroll is enabled for four viewcontrollers
any one know this plz answer this problem
Upvotes: 2
Views: 4955
Reputation: 81
I realize that it's quite an old question. But now you can use UIPageViewController
.
Upvotes: 0
Reputation: 1032
yes, you can just add the views of the viewcontrollers to your scrolling view, but remember that you are rolling your own equivalent to a UITabBarController or UINavigationController and so you have some responsibilities:
When you alloc init your vc from a nib the vc will get its viewDidLoad method called.
But when you put the vc.view into your scrollview YOU need to call [vc viewDidAppear:YES] (and also call viewWillAppear just before if your vc uses it).
Be careful with things like presenting modal view controllers from your vc as this may not work as you expect.
Peter
Upvotes: 3
Reputation: 10255
Just add them. What's the problem?
// this loads a view controller from a nib
controller = [[UIViewController alloc] initWithNibName:@"YourNibsName" bundle:nil];
// this adds the viewcontroller's view to the scrollview
[scrollView addSubview:controller.view];
// place the subview somewhere in the scrollview
CGRect frame = controller.view.frame;
frame.origin.x = 600;
controller.view.frame = frame;
// don't forget to release the viewcontroller somewhere in your dealloc
[controller release];
Do this for all your four controllers.
Upvotes: 10