执行从Xib到ViewContoller的segue

时间:2016-02-23 15:53:23

标签: xcode swift

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

@IBAction func buttonAction(sender: UIButton)
{
 self.performSegueWithIdentifier("SegueToPostDetail", sender: sender)
}

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

谢谢!

1 个答案:

答案 0 :(得分:5)

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

  1. 按下UIViewController中的按钮,单击该按钮调用performSegueWithIdentifier。
  2. 在Xib类中创建委托,UIViewController类实现该委托协议。 How do I set up a simple delegate to communicate between two view controllers?