1

I am creating an iOS application in which I want to perform an assignment action in button press before running the method prepareForSegue.

I created all controls using Main Story board.

The order of execution for some buttons is button press action -> prepareForSegue

but for some buttons it is prepareForSegue-> button press action

How to change the order for second set of buttons?

Here is the code I am using:

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")
        }
    }
}
Lorenzo
  • 3,293
  • 4
  • 29
  • 56
Parth Tiwari
  • 855
  • 2
  • 9
  • 23
  • 2
    Remove the storyboard segue from the button in Interface Builder, Carl-drag from the view controller object (orange box) to the destination scene and name that segue. The in your code call `performSegueWithIdentifier` – Paulw11 Nov 01 '15 at 19:32

1 Answers1

2

I figured out the problem, when give then code in this way, the execution is just alphabetical order, all the other methods were getting executed before prepareForSegue because the methods come above in alphabetical order

When I renamed the quiz and settings methods as a_quiz and a_settings, it worked

Parth Tiwari
  • 855
  • 2
  • 9
  • 23