作者:纸灰机forever | 来源:互联网 | 2023-05-19 13:57
Xcode6interfacebuilderbydefaulthasnewcheckboxusesizeclasses.Itmakesviewsadaptive.
Xcode 6 interface builder by default has new checkbox "use size classes". It makes views adaptive.
Xcode 6接口构建器默认有新的复选框“使用大小类”。它使自适应的看法。
When I try to make segue between 2 views in my storyboard I have new options:
当我试图在我的故事板中的两个视图之间进行segue时,我有了新的选项:
instead old:
而不是老:
Now we have "show" and "present modally" instead of "push" and "modal". The old options are marked as deprecated. I've chosen "show" option, because in segue settings it called "show (e.g. push)
现在我们有“show”和“present modally”而不是“push”和“modal”。旧的选项被标记为弃用。我选择了“show”选项,因为在segue的设置中它被称为“show(例如push)”
But it doesn't make push. Segue animation looks like slide from the bottom (modal) and navigation bar disappears.
但它不会推。Segue动画从底部(模式)和导航栏消失。
Question is: How can I make "show" work like push? Is it possible or should I use "push (deprecated)" instead? Where can I find any information about new types of segue? The only thing that I've found in iOS8 developer library is Storyboards Help You Design Your User Interface but there is no information about "show" segue.
问题是:我怎样才能让“显示”工作像push?是可能的还是应该使用“push(弃用)”呢?在哪里可以找到关于新类型segue的信息?我在iOS8 developer library中发现的唯一一件事是storyboard帮助您设计用户界面,但是没有关于“show”segue的信息。
UPDATE
I tried to create new project and "show" is really works like "push". I think the issue in my project can be because I reuse navigation controller with code like this, but I don't know how to fix it.
我试着创建一个新的项目,“show”真的很像“push”。我认为我的项目中的问题可能是因为我重用了像这样代码的导航控制器,但我不知道如何修复它。
if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] ) {
SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;
swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {
UINavigationController* navCOntroller= (UINavigationController*)self.revealViewController.frontViewController;
[navController setViewControllers: @[dvc] animated: NO ];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
};
}
After that I try to push NewViewController after MainViewController
之后,我尝试在MainViewController之后推出NewViewController。
UPDATE 2:
I seems to be only iOS 7, iOS 7.1 issue.
我似乎只是ios7, iOS 7.1的问题。
7 个解决方案
32
There is already an accepted answer, but I wanted to give a bit more information, possibly information that was not available before.
已经有了一个公认的答案,但是我想要提供更多的信息,可能是以前没有的信息。
As was mentioned previously, the "push" and "modal" segues were deprecated, and have been replaced by "show" and "present modally" respectively. According to Apple's documentation, the new segues have been further divided into segues that adapt to size classes. The older ones should only be used to support iOS versions older than iOS 8.
如前所述,“push”和“modal”segue被弃用,分别被“show”和“present modally”取代。根据苹果公司的文档,新的segue被进一步划分为适应大小类的segue。旧的版本应该只支持iOS 8版本的iOS版本。
The document in the following link explains that and the description of all the available segues, old and new.
下面链接中的文档解释了所有可用segue的描述,旧的和新的。
Adding a Segue Between Scenes in a Storyboard
在故事板中的场景之间添加一个Segue。
In case the URL changes in the future, this is the explanation given for each new segue:
如果将来URL发生了变化,这是为每个新segue提供的解释:
Show
Present the content in the detail or master area depending on the content of the screen. If the app is displaying a master and detail view, the content is pushed onto the detail area. If the app is only displaying the master or the detail, the content is pushed on top of the current view controller stack.
根据屏幕内容显示细节或主区域的内容。如果应用程序显示一个主视图和细节视图,则将内容推送到细节区域。如果该应用程序只是显示master或detail,则将内容推送到当前视图控制器堆栈的顶部。
Show Detail
Present the content in the detail area. If the app is displaying a master and detail view, the new content replaces the current detail. If the app is only displaying the master or the detail, the content replaces the top of the current view controller stack.
在细节区域显示内容。如果应用程序显示一个主视图和细节视图,那么新的内容将取代当前的细节。如果应用程序只是显示master或detail,则内容将替换当前视图控制器堆栈的顶部。
Present Modally
Present the content modally. There are options to choose a presentation style (UIModalPresentationStyle) and a transition style (UIModalTransitionStyle).
模式的内容。有一些选项可以选择表示样式(UIModalPresentationStyle)和转换样式(UIModalTransitionStyle)。
Present as Popover
Present the content as a popover anchored to an existing view. There is an option to specify the possible directions of the arrow shown on one edge of the popover view (UIPopoverArrowDirection). There is also an option to specify the anchor view.
将内容作为弹出窗口锚定到现有视图。有一个选项可以指定在弹出窗口(UIPopoverArrowDirection)的一个边缘上显示的箭头的可能方向。还有一个选项可以指定锚视图。
23
tldr; Delete the Segue that is not pushing correctly and recreate it in the storyboard by dragging from a UIView/UIControl to the target view controller.
tldr;通过从UIView/UIControl拖动到目标视图控制器,删除没有正确推送的Segue并在故事板中重新创建它。
There is nothing wrong with the other answers but this one explains what is happening, how you can verify that it is happening and how to mitigate the issue in the future.
其他的答案并没有什么错,但是这一个解释了正在发生的事情,你如何验证它正在发生,以及如何在未来缓解这个问题。
Background
背景
In my case, none of my Show Segues were working even though I already had a UINavigationController as my initial view controller (with my content UIViewController as it's root).
在我的例子中,虽然我已经有一个UINavigationController作为我的初始视图控制器(我的内容UIViewController是root),但是我的Show Segues没有一个是工作的。
Why and How the Show Segue Breaks
为什么和如何显示Show Segue中断?
The Show segue breaks when it has an action associated with the segue within the storyboard's source xml. A typical scenario causing this might be if you have redefined a segue from a manual segue previously called in code. This leaves the following bits in the storyboard xml.
当在故事板的源xml中有一个与segue关联的动作时,Show segue中断。一个典型的场景可能是,如果您从以前调用的手动segue重新定义了一个segue。这将在故事板xml中留下以下部分。
Nota Bene To view storyboard as xml; Right click the storyboard file and choose Open as > Source Code. To revert use Open as > Interface Builder - Storyboard
Nota Bene将故事板视为xml;右键单击故事板文件,选择Open作为>源代码。恢复使用Open作为>界面构建器-故事板。
To accommodate any custom actions when using the segue from the storyboard one can just tap into prepareForSegue and intercept the destination view controller and call any methods from that location. In any case, the side effect for this little bug (the bug is the fact that when you redefine the segue it is not properly setup in xml ~ i.e. the action remains even after your change the segue to one that operates from a UIView (or UIControl) to a target view controller).
为了适应任何自定义操作,当使用从故事板中使用segue时,你只需点击prepareForSegue并截获目标视图控制器,并从该位置调用任何方法。在任何情况下,它的副作用小错误(bug是这样一个事实,当你用xml定义segue不正确设置~即行动仍然是即使你改变segue从UIView一个操作(或UIControl)目标视图控制器)。
Unfortunately the most direct solution fails. So just removing the xml attribute for the action from within the Storyboard will NOT fix the problem. Instead one has to simply delete and recreate the segue in the storyboard.
不幸的是,最直接的解决方案失败了。因此,从故事板中删除操作的xml属性将不会解决问题。相反,我们必须在故事板中简单地删除和重新创建segue。
When recreated the storyboard xml will no longer have an action associated with the particular segue and the Show will execute as a Push.
当重新创建故事板时,xml将不再具有与特定segue相关联的操作,而Show将作为Push执行。
Sample Xml for correct Show Segue
用于正确显示Segue的示例Xml。
Mitigation
缓解
To prevent recurrence one just needs to stick to non-manual storyboard segues if possible by using the prepareForSegue to add required actions based on destination view controller. Or if you must to mix and match, take the precaution to verify that your Show segues do not have any actions attached in the storyboard xml. If you are dealing with older projects then you should give special attention to the Storyboard source code as I've discovered a few issues.
为了防止递归,只要使用prepareForSegue来添加基于目标视图控制器的所需操作,就需要使用非手工故事板segue。或者,如果您必须混合和匹配,则采取预防措施来验证您的Show segues没有在故事板xml中附加任何操作。如果您正在处理较老的项目,那么您应该特别注意故事板源代码,因为我已经发现了一些问题。
2
I had the same issue with segues in Xcode 7 and iOS 7.1.2. Show segues (new feature from iOS 8) works like modal segues in iOS 7 and do not allow you to push your View Controllers into the Navigation Controller stack when you define segue type with Xcode in your Storyboard. That's why your self.navigationController will return nil, because the View Controller was not pushed to the stack and you can not pop it.
在Xcode 7和ios7.1.2中,我也遇到了同样的问题。显示segue (iOS 8的新特性)就像ios7中的模态segue一样,当你在故事板中定义segue类型时,不允许你将视图控制器推送到导航控制器堆栈中。这就是为什么你自己。navigationController将返回nil,因为视图控制器没有被推送到堆栈中,所以不能弹出它。
I don't understand why Apple did not add any notifications for this case in Xcode when you need your app to work on iOS 7. They say that Push method is Deprecated, but Show does not work correctly with iOS 7.
我不明白为什么苹果没有在Xcode中为这个案例添加任何通知,因为你需要你的应用在ios7上工作。他们说Push方法是不赞成的,但是在ios7中显示不能正常工作。
What have i did to resolve the issue:
我做了什么来解决这个问题:
I have created MYShowSegue class with .h
我使用.h创建了MYShowSegue类。
#import
@interface MYShowSegue : UIStoryboardSegue
@end
And .m file with only one perform method:
和。m文件只有一个执行方法:
#import "MYShowSegue.h"
@implementation MYShowSegue
- (void) perform {
if ([[[self sourceViewController] navigationController] respondsToSelector:@selector(showViewController:sender:)]) {
id sender = nil;
[[[self sourceViewController] navigationController] showViewController:[self destinationViewController] sender:sender];
}else{
[[[self sourceViewController] navigationController] pushViewController:[self destinationViewController] animated:YES];
}
}
@end
Than you need to set a Custom type for each segue in your Storyboard and select a new class for it, in my case it was MYShowSegue.
您需要为故事板中的每个segue设置一个自定义类型,并为它选择一个新类,在我的例子中是MYShowSegue。
Custom Segue Example
自定义Segue例子
This solution will help you to get a full support of your iOS 7 apps, they will use pushViewController method to push your Views and for iOS 8,9 etc. your segue will work with new (iOS 8) method showViewController
这个解决方案将帮助您得到您的iOS 7应用程序的完全支持,他们将使用pushViewController方法来推送您的视图,对于iOS 8、9等,您的segue将使用新的(ios8)方法showViewController。
Do not forget to do the same with all your segues in your Storyboard.
不要忘记在故事板中使用所有的segue。