简体   繁体   English

从另一个情节提要中推视图控制器时,导航栏将被删除

[英]Navigation bar is removed when pushing a viewcontroller from another storyboard

I have many storyboards in my project to have modules with specific functionalities. 我的项目中有许多情节提要,其中包含具有特定功能的模块。 In one of my storyboard, I have a navigation controller, which push the initial view controller of another storyboard. 在我的一个情节提要中,我有一个导航控制器,该控件推另一个情节提要的初始视图控制器。 When I push it, the navigation bar is removed and there is no way to get this specific bar back. 当我按下它时,导航栏将被删除,并且无法恢复该特定的栏。 When I put another navigation controller in my new storyboard, the navigation bar is resetted with an ugly transition (it comes from the right and replace the older one). 当我在新的情节提要板上放置另一个导航控制器时,导航栏将重置为一个丑陋的过渡(它来自右侧,并替换了较旧的版本)。

This is how I push my new storyboard's view controller : 这就是我推送新情节提要的视图控制器的方式:

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

UIStoryboardSegue *segue = [[GDFromRightCustomSegue alloc] initWithIdentifier:aSegueIdentifier source:aSource destination:SideBarInitialViewController];
[segue perform];

I perform a custom segue as well to get rid of the basic animation (the view coming from below) : 我也执行自定义segue来摆脱基本动画(视图来自下面):

UIView *sourceView = [self.sourceViewController view];
UIView *destinationView = [self.destinationViewController view];

CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;

destinationView.frame = CGRectMake(screenWidth, 0.0, screenWidth, screenHeight);

UIWindow *window = [[UIApplication sharedApplication] keyWindow];
[window insertSubview:destinationView aboveSubview:sourceView];

[UIView animateWithDuration:0.4 animations:^{
    destinationView.frame = CGRectOffset(destinationView.frame, -screenWidth, 0.0);
    sourceView.frame = CGRectOffset(sourceView.frame, -screenWidth, 0.0);

} completion:^(BOOL finished){
    [self.sourceViewController presentViewController:self.destinationViewController animated:false completion:nil];
}];

Is there a way to push the new storyboard without animate the navigation bar, or even better, to have the older navigation controller in my new storyboard ? 有没有办法使新的情节提要板没有动画化导航栏,或者甚至更好,以便在我的新情节提要板中安装旧的导航控制器?

In your source storyboard drag a new UIViewController and then drag a ** Modal segue** to this new UIViewController from your source ViewController. 在源情节提要中 ,拖动一个新的UIViewController ,然后从 ViewController中将“模态” **拖动到此新的UIViewController中 Click on this segue and then in the attributes Inspector add a Identifier of segue (let say " newSegue ") Identifier must be unique. 单击此segue,然后在属性Inspector中添加segue的标识符(让我们说“ newSegue ”),标识符必须是唯一的。 Also set segue type to " Custom " and write " newSegue " in Segue Class 还将 segue类型设置为“ Custom ”,并在Segue类中输入newSegue

Now add a catagory on UIStoryBoardSegue with name newSegue and in the .m file write these two methods. 现在在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];

}

Now in your source ViewController when you want to presenth new View Controller write this line 现在在您的源ViewController中,当您要展示新的View Controller时,请写以下行

[self performSegueWithIdentifier:@"newSegue" sender:nil];

Must Remember to replace "YourDestinationStoryBoardName" with your actual destination StoryBoard name in the above function. 必须记住,在上述函数中,将“ YourDestinationStoryBoardName”替换为实际的目标StoryBoard名称。

Try this Hope this will work fine. 试试这个,希望它能正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 按下ViewController时导航栏正在重置 - Navigation Bar is resetting when pushing a ViewController 推送到下一个viewController时导航栏消失 - Navigation bar disappears when pushing to the next viewController 在故事板上的第二个ViewController中无法访问iOS 8导航栏 - iOS 8 Navigation Bar Not Accessible in Second ViewController on Storyboard 从Tabbar Storyboard推送到另一个Storyboard问题 - Pushing from Tabbar Storyboard to another Storyboard issue 从另一个 ViewController 呈现故事板 ViewController - Present storyboard ViewController from another ViewController 当从一个ViewController到另一个ViewController执行show segue时,导航栏消失了? - Navigation bar disappears when show segue is executed from one ViewController to another? 如何将数据从导航栏上的右键传输到另一个 ViewController? - How to transfer the data from a right button on Navigation Bar to another ViewController? 从右侧的动态导航控制器推送视图控制器 - pushing a viewcontroller from the right, dynamic navigation controller 情节提要导航-从堆栈中推送和删除 - Storyboard navigation - pushing and removing from stack iOS导航问题:按下ViewController后,其结果是在导航栏中显示先前ViewController的导航项 - iOS navigation issue: after pushing a ViewController, it results in a navigation bar showing the navigation items of the previous ViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM