执行从 Xib 到 ViewContoller 的 segue [英] Perform a segue from an Xib to ViewContoller
本文介绍了执行从 Xib 到 ViewContoller 的 segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带按钮的 Xib 文件.单击按钮时,我想转到另一个视图控制器.我在 StoryBoard 中的视图控制器之间创建了一个 segue 并创建了一个标识符,但似乎无法以编程方式调用它.
I have a Xib file with a button. I want to segue to another view controller when the button is clicked. I've created a segue between the view controllers in StoryBoard and created an identifier, but can't seem to call it programatically.
@IBAction func buttonAction(sender: UIButton)
{
self.performSegueWithIdentifier("SegueToPostDetail", sender: sender)
}
Xcode 错误是....没有成员 'performSequeWithIdentifier'
Xcode error is "....has no member 'performSequeWithIdentifier'
谢谢!
推荐答案
不能在 Xib 类中调用 performSegueWithIdentifier,只能在 UIViewController 类中调用.所以你有两个解决方案:
You can't call performSegueWithIdentifier in a Xib class, only in a UIViewController class. So you have 2 solutions:
- 在 UIViewController 中有按钮,当点击按钮时调用 performSegueWithIdentifier.
- 在 Xib 类中创建一个委托,UIViewController 类实现该委托协议.如何设置一个简单的委托来在两个视图控制器之间进行通信?
这篇关于执行从 Xib 到 ViewContoller 的 segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文