0

I am using a barcode scanner to grab a barcode and then I want to segue to my next screen right after that barcode is grabbed and I use that to find some specific data. The scanning works fine, and when the barcode is scanned The method DidScanBarcode is hit and runs through, is in this method that I try and perform my segue but the app either freezes or crashes without ever performing the segue and the method PrepareForSegue is never hit after the PerformSegue is run. Any thoughts?

using Foundation;
using System;
using System.CodeDom.Compiler;
using UIKit;
using RedLasterPrototype;
using System.Threading.Tasks;
using CoreGraphics;
using ZXing.Mobile;
using ScanditSDK;



namespace Prototype
{
    partial class ScanViewController : UIViewController
    {
        public static ProductElement ScannedProduct { get; set; } 
        ScanditDelegate scanditDelegate; 

        public static string appKey = "xxxxx";

        public ScanViewController(IntPtr handle) : base (handle)
        {
        }

        public async override void ViewDidLoad() 
        {

            var picker = new ScanditSDK.SIBarcodePicker (appKey);
            scanditDelegate = new ScanditDelegate ();
            picker.OverlayController.Delegate = scanditDelegate;


            PresentViewController (picker, true, null);
            picker.StartScanning ();
         }
        public static ProductElement GetScannedData(string upc) 
        {
            var _service = new RestService ();
            var data = _service.GetDataFromUpc (upc);

            if (data != null) 
            {
                return data;

            }

            return null; 
        }


        public override void PrepareForSegue (UIStoryboardSegue segue, NSObject sender)
        {
            base.PrepareForSegue (segue, sender);

            if (segue.Identifier == "SegueToProductPage") 
            {
                var destination = (ScannedProductViewController)segue.DestinationViewController;
            destination.product = ScannedProduct;

        }
    }
    public class ScanditDelegate : SIOverlayControllerDelegate
    {
        public override void DidScanBarcode (SIOverlayController overlayController, NSDictionary barcode) {
            // perform actions after a barcode was scanned
            Console.WriteLine ("barcode scanned: {0}, '{1}'", barcode["symbology"], barcode["barcode"]);

            var code = barcode ["barcode"].ToString();
            if(code != null)
            {
                ScannedProduct = GetScannedData (code);
                var x = new ScanViewController (this.Handle);
                x.PerformSegue ("SegueToProductPage", this);
            }

        }

        public override void DidCancel (SIOverlayController overlayController, NSDictionary status) {
            // perform actions after cancel was pressed
        }

        public override void DidManualSearch (SIOverlayController overlayController, string text) {
            // perform actions after search was used
        }
    }

}


}
Billy
  • 823
  • 3
  • 12
  • 28
  • DidScanBarcode is creating a NEW instance of your VC and attempting to use it for the segue. Instead, you need to dismiss the Picker you created in ViewDidLoad and then call the segue from the instance of the VC that already exists. – Jason Mar 21 '16 at 21:27
  • If i take out the new instance of my VC, how would I call the segue from the original instance of the VC? – Billy Mar 21 '16 at 21:33
  • 1
    Pass a reference to your VC when you create your delegate; or pass a delegate function to be executed after the scan completes – Jason Mar 21 '16 at 21:46

0 Answers0