为什么不执行Segue

时间:2019-06-30 00:27:27

标签: ios swift uigesturerecognizer

我认为我想使用户可以交互,当用户触摸他时,他会执行对话。为什么代码不起作用。

@IBOutlet weak var HistoryCategory: UIView!
    var historyTapGesture: UIGestureRecognizer!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.historyTapGesture = UIGestureRecognizer(target: nil, action: #selector(chooseCategoryViewController.openHistoryQuest(tap:)))
        HistoryCategory.isUserInteractionEnabled = true
        HistoryCategory.addGestureRecognizer(historyTapGesture)
        // Do any additional setup after loading the view.
    }
    @objc func openHistoryQuest(tap: UIGestureRecognizer) {
        performSegue(withIdentifier: "history", sender: nil)
    }

1 个答案:

答案 0 :(得分:1)

请不要忘记您的视图控制器类是执行Segue的类,因此您需要将“ self”设置为目标和发送者,并如@rmaddy所述将其设置为轻击手势识别器。

只需替换这两行:

self.historyTapGesture = UIGestureRecognizer(target: nil, action: #selector(chooseCategoryViewController.openHistoryQuest(tap:)))


performSegue(withIdentifier: "history", sender: nil)

使用:

self.historyTapGesture = UITapGestureRecognizer(target: self, action: #selector(chooseCategoryViewController.openHistoryQuest(tap:)))


performSegue(withIdentifier: "history", sender: self)