2015-11-01 57 views
1

我正在創建一個iOS應用程序,在該應用程序中,我想在運行方法prepareForSegue之前按按鈕執行賦值操作。如何在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

從在界面生成器,從視圖控制器對象卡爾拖動按鈕卸下故事板SEGUE(橙色框)到目的地的場景和名稱。在你的代碼中調用'performSegueWithIdentifier' – Paulw11

回答

1

,執行只是按字母順序排列,所有其他的方法進行prepareForSegue之前得到執行,因爲上述方法來按字母順序

當我改名爲測驗和設置方法爲a_quiz和a_settings,它的工作

相關問題