[英]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.