Ios 从另一个情节提要中推送viewcontroller时,导航栏将被删除

Ios 从另一个情节提要中推送viewcontroller时,导航栏将被删除,ios,objective-c,iphone,cocoa-touch,uinavigationcontroller,Ios,Objective C,Iphone,Cocoa Touch,Uinavigationcontroller,在我的项目中,我有许多故事板,其中包含具有特定功能的模块。在我的一个故事板中,我有一个导航控制器,它推送另一个故事板的初始视图控制器。当我按下它时,导航栏被移除,并且没有办法将此特定栏取回。当我在我的新故事板中放置另一个导航控制器时,导航栏被重置为一个丑陋的过渡(它来自右侧并替换旧的) 这就是我推送新故事板视图控制器的方式: UIStoryboard *storyboard = [UIStoryboard storyboardWithName:aStoryboardName bundle:nil

在我的项目中,我有许多故事板,其中包含具有特定功能的模块。在我的一个故事板中,我有一个导航控制器,它推送另一个故事板的初始视图控制器。当我按下它时,导航栏被移除,并且没有办法将此特定栏取回。当我在我的新故事板中放置另一个导航控制器时,导航栏被重置为一个丑陋的过渡(它来自右侧并替换旧的)

这就是我推送新故事板视图控制器的方式:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:aStoryboardName bundle:nil];
UIViewController *SideBarInitialViewController = [storyboard instantiateInitialViewController];

UIStoryboardSegue *segue = [[GDFromRightCustomSegue alloc] initWithIdentifier:aSegueIdentifier source:aSource destination:SideBarInitialViewController];
[segue perform];
我还执行了一个自定义的segue,以摆脱基本动画(下面的视图):


有没有一种方法可以在不设置导航栏动画的情况下推送新的故事板,或者更好,要在我的新故事板中使用旧的导航控制器?

在源故事板中拖动一个新的UIViewController,然后从ViewController中将**模式段**拖动到此新的UIViewController。单击此segue,然后在属性检查器中添加segue的标识符(比如“newSegue”),标识符必须是唯一的。还将segue type设置为“Custom”并在segue类中写入“newSegue

现在在UIStoryBoardSegue上添加一个名为newSegue的分类,并在.m文件中编写这两种方法

- (id) initWithIdentifier:(NSString *)identifier
                   source:(UIViewController *)source
              destination:(UIViewController *)destination
{
    return [super initWithIdentifier:identifier
                              source:source
                         destination:[[UIStoryboard storyboardWithName:@"YourDestinationStoryBoardName" bundle:nil] instantiateInitialViewController ]];
}

- (void)perform
{

    UIViewController *source = (UIViewController *)self.sourceViewController;

   [source presentViewController:self.destinationViewController
                                          animated:YES
                                        completion:Nil];

}
现在,在源视图控制器中,当您要呈现新的视图控制器时,请编写以下行

[self performSegueWithIdentifier:@"newSegue" sender:nil];
必须记住在上述函数中用实际的目标情节提要名称替换“YourDestinationStoryBoardName”


尝试此方法,希望效果良好。

在源代码情节串连板中拖动一个新的UIViewController,然后从源代码中拖动一个**模式序列**到这个新的UIViewController。单击此segue,然后在属性检查器中添加segue的标识符(比如“newSegue”),标识符必须是唯一的。还将segue type设置为“Custom”并在segue类中写入“newSegue

现在在UIStoryBoardSegue上添加一个名为newSegue的分类,并在.m文件中编写这两种方法

- (id) initWithIdentifier:(NSString *)identifier
                   source:(UIViewController *)source
              destination:(UIViewController *)destination
{
    return [super initWithIdentifier:identifier
                              source:source
                         destination:[[UIStoryboard storyboardWithName:@"YourDestinationStoryBoardName" bundle:nil] instantiateInitialViewController ]];
}

- (void)perform
{

    UIViewController *source = (UIViewController *)self.sourceViewController;

   [source presentViewController:self.destinationViewController
                                          animated:YES
                                        completion:Nil];

}
现在,在源视图控制器中,当您要呈现新的视图控制器时,请编写以下行

[self performSegueWithIdentifier:@"newSegue" sender:nil];
必须记住在上述函数中用实际的目标情节提要名称替换“YourDestinationStoryBoardName”


试试这个,希望效果会很好。

谢谢您的回答!这项工作相当不错,但有没有办法不将其作为堆栈(使用“后退”按钮)来获取?我的意思是,我想要一个精确的古代导航控制器。你可以使用模态序列。我正在编辑答案,以便你可以再次查看。使用这一行[source presentViewController:self.destinationViewController animated:YES completion:Nil];使用此行[源presentViewController:self.destinationViewController动画:是完成:无];在执行方法中,当显示viewcontroller时,导航控制器将被擦除!这真的是一个模式序列吗?是的,当你以模式呈现ViewController时,导航控制器会被擦除,所以如果你想保留导航控制器,那么你应该使用Push segue。谢谢你的回答!这项工作相当不错,但有没有办法不将其作为堆栈(使用“后退”按钮)来获取?我的意思是,我想要一个精确的古代导航控制器。你可以使用模态序列。我正在编辑答案,以便你可以再次查看。使用这一行[source presentViewController:self.destinationViewController animated:YES completion:Nil];使用此行[源presentViewController:self.destinationViewController动画:是完成:无];在执行方法中,当显示viewcontroller时,导航控制器将被擦除!它真的是一个模式序列吗?是的,当你以模式呈现ViewController时,导航控制器被擦除,所以如果你想保留导航控制器,那么你应该使用Push序列。