0

I come here with a very very strange error.

I have 3 View controllers in my storyboard.

1) Main Page with list of products ViewController

2) Single Product Detail ProductViewController

3) Barcode scanner BarcodeViewController

In the MAIN and PRODUCT DETAIL ViewController, i have a button saying "Scan Barcode" on top.

I first coded the button of "Scan Barcode" in the ViewController and segue it to the BarcodeViewController. It works perfectly.

For the same Scan Button in ProductViewController, i coded it differently. I drag the button to EXIT. So that the ViewController loads again and as soon as it is loaded i programmatically load the Barcode scanner.

It does not work. There is no error, there is no crash, nothing. Even Prepare for segue function is called. It goes into the right block everywhere. Just the BarcodeViewController dont show up.

The code in ViewController

@IBAction func returned (segue: UIStoryboardSegue) {

    NSLog("Returned Segue \(segue.identifier)")

    if ( segue.identifier == "unwindToMainViewViaBarcode" )
    {
        dispatch_async(dispatch_get_main_queue(), {
            self.performSegueWithIdentifier(self.segueIdentifierForBarcode, sender: nil)
        });
    }
}


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    NSLog("PrepareForSegue \(segue.identifier)")

    if ( segue.identifier == segueIdentifierForBarcode )
    {
        // Reset barcode String
        barcodeString = ""

        // get reference for ViewController and set as a var
        let destination = segue.destinationViewController as! BarcodeViewController
        destination.mainView = self;
        print("open barcode called")
    }

}
princ___y
  • 1,089
  • 1
  • 9
  • 27
Sallu
  • 479
  • 6
  • 17
  • because ur unwind segue havnt finish yet, u cant call another one right after that – Tj3n Dec 04 '15 at 04:58
  • Present Modally works best. I have to code a button function only in ViewController and in every where else i just return. It saves me time in coding :) – Sallu Dec 04 '15 at 05:05

2 Answers2

1

U can refer so some answer in this SO Answer

Basically make a BOOL before perform unwind segue and check it at ViewDidAppear, if its set then perform segue from there and turn the BOOL to false

Community
  • 1
  • 1
Tj3n
  • 9,837
  • 2
  • 24
  • 35
  • This is a very very good answer. If i find issue again, i think i will try this. So far my PRESENT MODALLY works. – Sallu Dec 04 '15 at 05:08
0

I found the problem. In other projects it is working because I am showing segue Modally Here i by mistake was just showing it.

Now that i have changed it to show as Modal It is working fine.

Sallu
  • 479
  • 6
  • 17