开发者

Can you have two Navigation Controllers in subviews of a Main UIViewController?

开发者 https://www.devze.com 2023-01-05 09:50 出处:网络
The following image explains what I\'m trying to do: http://img337.imageshack.us/img337/1475/multinav.png

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>;
}
0

精彩评论

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

关注公众号