如何在iOS中的prepareForSegue之前执行按钮按下操作?

时间:2015-11-01 19:29:42

标签: ios swift segue

我正在创建一个iOS应用程序,我想在按下按钮之前执行一个赋值操作,然后再运行方法prepareForSegue。

我使用主要故事板创建了所有控件。

某些按钮的执行顺序是 按钮按下动作 - > prepareForSegue

但是对于某些按钮来说 prepareForSegue->按钮按下动作

如何更改第二组按钮的顺序?

以下是我正在使用的代码:

import UIKit

class SummaryViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    var button_prsd = "none"

    @IBAction func people_insights(sender: AnyObject) {
        button_prsd = "people_insights"
    }

    @IBAction func industry_research(sender: AnyObject) {
        button_prsd = "industry_research"
    }

    @IBAction func holidays_events(sender: AnyObject) {
        button_prsd = "holidays_events"
    }

    @IBAction func monthly_spotlights(sender: AnyObject) {
        button_prsd = "monthly_spotlights"
    }

    @IBAction func blog(sender: AnyObject) {
        button_prsd = "blog"
    }


    @IBAction func about_us(sender: AnyObject) {
        button_prsd = "about_us"
        print("button press about us executed")
    }


    @IBAction func settings(sender: AnyObject) {
        button_prsd="settings"
        print("button press settings executed")

    }


    @IBAction func quiz(sender: AnyObject) {
        button_prsd="quiz"
        print("button press quiz executed")
    }

    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.

        let next_view = segue.destinationViewController

        if(next_view is DetailViewController)
        {
            let det_view = next_view as! DetailViewController
            det_view.link = button_prsd
            print("segue executed")
        } else if(next_view is DetailTableViewController)
        {
            let det_view = next_view as! DetailTableViewController

            print("segue executed")
        }
    }
}

1 个答案:

答案 0 :(得分:2)

我想出了问题,当以这种方式给出代码时,执行只是字母顺序,所有其他方法都在prepareForSegue之前执行,因为方法按字母顺序排在上面

当我将测验和设置方法重命名为a_quiz和a_settings时,它起作用了

相关问题