我已经以编程方式创建了一个名为“菜单”的按钮。它被改为一个名为' menuButton'的UIBarButtonItem。单击按钮时,我想使用performSegueWithIdentifier调用segue。
Universal.swift
struct UniversalStatic {
static let data = Universal()
}
public class Universal {
let menuButton : UIBarButtonItem
let menu : UIButton
init(){
menu = UIButton(type: UIButtonType.Custom)
menu.setImage(UIImage(named: "menu.png"), forState: UIControlState.Normal)
menu.frame = CGRectMake(0, 0, 25, 20)
menuButton = UIBarButtonItem(customView: menu)
}
HomeViewController.swift
class HomeViewController: UIViewController {
func goToMenuVC() {
self.performSegueWithIdentifier("test", sender: self)
}
override func performSegueWithIdentifier(identifier: String, sender: AnyObject?) {
print("called")
}
override func viewDidLoad() {
super.viewDidLoad()
UniversalStatic.data.menu.addTarget(self, action: "goToMenuVC", forControlEvents: UIControlEvents.TouchUpInside)
self.navigationItem.leftBarButtonItem = UniversalStatic.data.menuButton
}
func viewDidAppear() {
UniversalStatic.data.menu.addTarget(self, action: "goToMenuVC", forControlEvents: UIControlEvents.TouchUpInside)
self.navigationItem.leftBarButtonItem = UniversalStatic.data.menuButton
}
打印了打印声明,因此我知道了'performSegueWithIdentifier'虽然被称为show segue是有益的。
答案 0 :(得分:1)
尝试添加:
super.performSegueWithIdentifier(identifier, sender: sender)
使用performSegueWithIdentifier
方法。