UINavigationController作为UINavigationController的子元素



我不知道标题是否解释了问题本身,但这里是…

我有一个UINavigationController它是UINavigationController的parentViewController。事情是childViewController行为奇怪,当我添加它作为一个孩子,它首先有状态栏的差距(它不占据整个屏幕),如果我"解决"的"bug"隐藏和显示导航栏,差距消失了,但现在孩子不尊重帧我手动设置。然后我试图继续,当我在子节点上呈现一个模态并取消它时,整个子节点就消失了…

有什么不对吗?和两个容器的亲子关系还是什么?

谢谢你的建议

编辑:这是一个展示奇怪行为的示例项目

http://www.mediafire.com/?8saa68daqfkf335

编辑2:我找到了一个解决方案,实际上,我没有发现它真的很清楚的苹果文档,它说的childViewControllers采取它的框架从parentViewController他们属于,但它没有说,如果parentViewController"重新出现"(像推它)的childViewControllers得到调整大小再次由parentViewController框架…希望对大家有所帮助

我认为将第二个导航视图控制器作为模态视图控制器呈现会更好。例如,将当前的presentController选择器替换为如下内容:

- (void)presentController:(id)sender {
ChildViewController1 *cvc = [[ChildViewController1 alloc] initWithNibName:@"ChildViewController1" bundle:nil];
nc3 = [[UINavigationController alloc] initWithRootViewController:cvc];
nc3.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:nc3 animated:YES completion:nil];
UIBarButtonItem *i = [[UIBarButtonItem alloc] initWithTitle:@"X" style:UIBarButtonItemStyleBordered target:self action:@selector(close)];
cvc.navigationItem.leftBarButtonItem = i;
}
那么,你的close选择器可以变成:
- (void)close {
[nc3 dismissViewControllerAnimated:YES completion:nil];
}

(虽然我建议移动按钮的创建和处理关闭实际上在ChildViewController1.m)。

当然,这将把所有的导航控制器的创建从ViewController中移除。m的viewDidLoad选择器:

- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blueColor];
UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];
b.frame = CGRectMake(0, 100, 100, 40);
[b setTitle:@"present" forState:UIControlStateNormal];
[b addTarget:self action:@selector(presentController:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:b];
}

希望它能起作用!

最新更新