gpt4 book ai didi

iphone - ChildViewController 推送而不是替换 Parent ViewController 中的 View

转载 作者:行者123 更新时间:2023-11-28 20:32:58 24 4
gpt4 key购买 nike

我有以下设置

http://i.minus.com/j6rhBqXOkRRjl.png

当我触摸其中一个按钮时,相应 targetViewController 的内容应该出现在按钮下方的白色框中。

这工作正常(请参阅下面的代码),但是一旦我将 ParentViewController 包含在导航 Controller 中,ViewController 就会推送到带有“First”标签的 View ,而不是将其添加到 ParentViewController View 的框中。

两个 segue 都定义为“自定义”,那么为什么会发生推送?

这是我显示 ViewControllers 的代码:

-(void)swapVC:(UIViewController *)newController{

if(_currentViewController){
[_currentViewController removeFromParentViewController];
}

[self addChildViewController:newController];
[self.contentView addSubview:newController.view];

[newController didMoveToParentViewController:self];
}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

if([segue.identifier isEqualToString:@"showFirst"]){

[self swapVC:segue.destinationViewController];
} else if([segue.identifier isEqualToString:@"showSecond"]){
[self swapVC:segue.destinationViewController];
}

}

最佳答案

你不应该使用 segue。当您想要切换 View Controller 时,请使用 transitionFromViewController:toViewController:duration:options:animation:completion 方法。 segue 将简单地将 View Controller 压入堆栈,可能是因为自定义 segue 未定义。

编辑:您可以将转场留在那里,但如果您执行它们,它将把它插入堆栈。

关于iphone - ChildViewController 推送而不是替换 Parent ViewController 中的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11582534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com