开发者

UIScrollView with multiple UIViewControllers

i have one scrollview and 4 UIviewcontrollers with xib files now i want to add 4 viewcontrollers to scrollv开发者_运维技巧iew

and also the scroll is enabled for four viewcontrollers

any one know this plz answer this problem


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.


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


I realize that it's quite an old question. But now you can use UIPageViewController.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜