【问题标题】:Perform a segue from an Xib to ViewContoller执行从 Xib 到 ViewController 的 segue
【发布时间】:2016-06-05 13:25:13
【问题描述】:

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

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

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

谢谢!

【问题讨论】:

  • 你在故事板中命名了 segue 吗?
  • 是的,我做到了。我读过您无法将 Xib 连接到情节提要以创建 segue,因此我通过情节提要连接了两个视图控制器。命名为标识符,现在我只是想在单击 Xib 上的按钮时以编程方式调用 segue。由于某种原因,我无法调用 performSegueWithIdentifier。说该成员不存在。

标签: xcode swift


【解决方案1】:

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

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

【讨论】:

  • 现在我为什么不能调用 performSegueWithIdentifier 是有道理的。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-30
  • 2019-03-17
  • 1970-01-01
  • 2015-08-04
  • 2015-10-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多