你可以在Main UIViewController的子视图中有两个导航控制器吗?

时间:2010-07-03 15:38:07

标签: iphone uiviewcontroller uinavigationcontroller uinavigationbar ipad

下图说明了我要做的事情:

http://img337.imageshack.us/img337/1475/multinav.png

这适用于iPad应用。可能吗?如果是这样,有人可以发布骨架代码吗?

提前致谢

1 个答案:

答案 0 :(得分:1)

是的,这是可能的。骨架代码:

标题文件:

@interface SGBSplitViewController : UIViewController

@property (nonatomic, strong, readonly) UIViewController *leftViewController;
@property (nonatomic, strong, readonly) UIViewController *rightViewController;

- (id)initWithLeftViewController:(UIViewController *)leftViewController
             rightViewController:(UIViewController *)rightViewController;

@end

实施档案:

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