xcode 无法连接 Storyboard Unwind Segue
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12792573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot Connect Storyboard Unwind Segue
提问by Chris Wagner
I am attempting to create an unwind segue but nothing will connect to it when ctrl+dragging. Also when I right click on the Exit icon there are no options available.
我正在尝试创建一个 unwind segue,但是当 ctrl+拖动时没有任何东西可以连接到它。此外,当我右键单击“退出”图标时,没有可用的选项。
Any ideas?
有任何想法吗?
回答by Jon Hess
You need to have an IBAction defined on a view controller that takes an argument of type "UIStoryboardSegue *".
您需要在视图控制器上定义一个 IBAction,该控制器采用“UIStoryboardSegue *”类型的参数。
Something like this:
像这样的东西:
@interface MyViewController
...
- (IBAction)unwindFromConfirmationForm:(UIStoryboardSegue *)segue {
}
...
@end
Swift 3 Version
斯威夫特 3 版本
@IBAction func unwindToViewController(segue: UIStoryboardSegue) {
//code
}
Provided by DoruChideanin https://stackoverflow.com/a/46199117/250190
由DoruChidean在https://stackoverflow.com/a/46199117/250190 中提供
回答by Travis M.
Just to clarify, to link this up in storyboard, after adding the above method to the "view controller you want to unwind to" you need to drag a segue from a button or whatever in your "view controller you want to unwind from" down to it's ownlittle green "EXIT" icon in the bottom bar.
只是为了澄清,要在情节提要中将其链接起来,在将上述方法添加到“您想要展开到的视图控制器”之后,您需要从按钮或“您想要从中展开的视图控制器”中的任何内容中拖出一个segue以它自己的小绿“EXIT”在底栏图标。
There should be a popup to link to "- unwindFromConfirmationForm".
应该有一个弹出窗口链接到“- unwindFromConfirmationForm”。
Once that's done, the unwind segue should work.
完成后,unwind segue 应该可以工作了。
Just adding to Travis excellent point: to be utterly clear:
只是添加到 Travis 的要点:完全清楚:
Say you've just started experimenting with storyboards so you (a) made a new iOS7 Xcode project and (b) made a story board with one navigation controller, and then (c) you've made five or six view controllers. You aim to be able to go-and-fore between the half-dozen view controllers using unwinds. {It is trivial to go "forward" by control-dragging from a button in one, to, the next one.}
假设您刚刚开始尝试故事板,因此您 (a) 制作了一个新的 iOS7 Xcode 项目,并且 (b) 制作了一个带有一个导航控制器的故事板,然后 (c) 您制作了五六个视图控制器。您的目标是能够使用 unwinds 在六个视图控制器之间来回切换。{通过控制拖动从一个按钮到下一个按钮来“前进”是微不足道的。}
Now, at this moment: all six of the view controllers, will indeed be the "default" class "ViewController". Note that Xcode (somewhat pointlessly) gives you a ViewController.h and ViewController.m file.
现在,此时:所有六个视图控制器确实将是“默认”类“ViewController”。请注意,Xcode(有点无意义)为您提供了一个 ViewController.h 和 ViewController.m 文件。
Again, all six of your "simple example" views are indeed just using that file ViewController.m, at this moment. So, very simply, if you add this:
同样,此时您的所有六个“简单示例”视图确实都在使用该文件 ViewController.m。所以,很简单,如果你添加这个:
-(IBAction)unwindUnused:(UIStoryboardSegue *)segue
{
NSLog(@"I did an unwind segway! Holy crap!");
}
To that one "stub" file ViewController.m - in fact, every one of your six views will now "work", you'll be able to drag to the infamous small green "Exit" button. It's that easy.
对于那个“存根”文件 ViewController.m - 事实上,您的六个视图中的每一个现在都将“工作”,您将能够拖动到臭名昭著的绿色小“退出”按钮。就这么简单。
Now just TBC normally in a real project, you'd never use the default "ViewController.m" file. So, go here:
现在只是在实际项目中通常为 TBC,您永远不会使用默认的“ViewController.m”文件。所以,去这里:
and find down to precisely "Create Custom View Controllers", and it of course explains that process in excellent detail if you're new.
并准确地找到“创建自定义视图控制器”,如果您是新手,它当然会非常详细地解释该过程。
But again, if you're just fooling around and want to make the green button work for unwinds, simply put the code fragment in the "ViewController.m" stub file, and you're away. (Remembering that in "real life" you'd put a custom such call in each of your custom screens - likely dealing with data, etc etc.) Hope it helps!!
但同样,如果您只是闲逛并想让绿色按钮用于展开,只需将代码片段放在“ViewController.m”存根文件中,您就可以离开了。(请记住,在“现实生活”中,您会在每个自定义屏幕中进行自定义此类调用 - 可能处理数据等)希望它有所帮助!!
Bonus factoid:Note that a "Back" button will, anyway, automatically appear on the navbar when you're just testing like this! (i.e., even if you don't add the unwind stub method.)
额外的事实:请注意,无论如何,当您像这样进行测试时,“返回”按钮将自动出现在导航栏上!(即,即使您不添加 unwind 存根方法。)
回答by DoruChidean
Upvote for Jon Hess! This is the swift 3 equivalent
为乔恩·赫斯点赞!这是 swift 3 等价的
@IBAction func unwindToViewController(segue: UIStoryboardSegue) {
//code
}
回答by Fred
Are your working with xcode6-beta version? in beta 1-3 is a bug which prevents interface builder from detecting unwind segues. in xcode6-beta4 this bug has been fixed.
您使用的是 xcode6-beta 版本吗?在 beta 1-3 中是一个错误,它阻止界面构建器检测展开转场。在 xcode6-beta4 中,此错误已修复。