在Swift中,我使用以下方式程序化地创建了一个按钮:
var button = UIBarButtonItem(title: "Tableau", style: .Plain, target: self, action: "tabBarTableauClicked")
我希望当用户点击按钮时,它可以更改视图控制器。
这里是tabBarTableauClicked
的代码:
func tabBarTableauClicked(){
performSegueWithIdentifier("tableau", sender: self)
}
但很明显它没有起作用,因为没有一个名为“tableau”的标识符的segue。
我无法使用Ctrl +点击按钮并拖动到第二个viewController来创建segue,因为按钮是以编程方式而不是在故事板中创建的。
我该如何在Swift中以编程方式创建带有标识符的segue?