Can you have two Navigation Controllers in subviews of a Main UIViewController?
The following image explains what I'm trying to do:
http://img337.imageshack.us/img337/1475/multinav.png
This is for an iPad app. Is it possible? And if so, can someone p开发者_JAVA技巧ost the skeleton code to do it?
Thanks in advance
Yes, it's possible. Skeleton code:
Header file:
@interface SGBSplitViewController : UIViewController
@property (nonatomic, strong, readonly) UIViewController *leftViewController;
@property (nonatomic, strong, readonly) UIViewController *rightViewController;
- (id)initWithLeftViewController:(UIViewController *)leftViewController
rightViewController:(UIViewController *)rightViewController;
@end
Implementation file:
@implementation SGBSplitViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
return nil;
}
- (id)initWithLeftViewController:(UIViewController *)leftViewController
rightViewController:(UIViewController *)rightViewController
{
self = [super initWithNibName:nil bundle:nil];
if (self)
{
_leftViewController = leftViewController;
_rightViewController = rightViewController;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self addChildViewController:self.leftViewController];
[self.view addSubview:self.leftViewController.view];
[self.leftViewController didMoveToParentViewController:self];
[self addChildViewController:self.rightViewController];
[self.view addSubview:self.rightViewController.view];
[self.rightViewController didMoveToParentViewController:self];
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.leftViewController.view.frame = <frame>;
self.rightViewController.view.frame = <frame>;
}
精彩评论