执行从Xib到ViewContoller的segue

Mar*_*oon 4 xcode swift

我有一个带按钮的Xib文件.单击按钮时,我想要转到另一个视图控制器.我在StoryBoard中的视图控制器之间创建了一个segue并创建了一个标识符,但似乎无法以编程方式调用它.

@IBAction func buttonAction(sender: UIButton)
{
 self.performSegueWithIdentifier("SegueToPostDetail", sender: sender)
}
Run Code Online (Sandbox Code Playgroud)

Xcode错误是"....没有成员'performSequeWithIdentifier'

谢谢!

Alv*_*aro 5

您不能在Xib类中调用performSegueWithIdentifier,只能在UIViewController类中调用.所以你有2个解决方案:

  1. 拥有UIViewController中的按钮,并在单击按钮时调用performSegueWithIdentifier.
  2. 在Xib类中创建委托,UIViewController类实现该委托协议.如何设置一个简单的委托来在两个视图控制器之间进行通信?