我以编程方式创建了一个名为“menu”的按钮,该按钮已更改为一个名为“menuButton”的UIBarButtonItem。单击按钮后,我想使用performSegueWithIdentifier调用segue。
通用雨燕
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”,但是显示序列是有益的。
我已附上segue标识符的屏幕截图。
最佳答案
尝试添加:
super.performSegueWithIdentifier(identifier, sender: sender)
在您的
performSegueWithIdentifier
方法中。关于ios - performSegueWithIdentifier未按预期显示 View Controller ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35606861/