2017-05-01 3 views
0

i von einem Code erzeugt, um eine Methode zu triggern versuchen ...Swift 3 IOS Access Class-Methode von dynamisch erstellte Schaltfläche

ich den Fehler: Der Wert des Typs: SBSbarcode Picker hat kein Mitglied StartScanning.

Wie können diese Schaltfläche Zugriff der oben genannten Methoden?

Jede Hilfe wäre willkommen. folgenden Code

class scanViewController: UIViewController { 

override func viewDidLoad() 
{ 
    super.viewDidLoad() 
    setupManualScanner() 
} 



func setupManualScanner() { 

    // Scandit Barcode Scanner Integration 
    // The following method calls illustrate how the Scandit Barcode Scanner can be integrated 
    // into your app. 

    // Create the scan settings and enabling some symbologies 
    let settings = SBSScanSettings.default() 

    let symbologies: Set<SBSSymbology> = [.code39, .code128] 
    settings.settings(for: .code128).activeSymbolCounts = [11,15,16,17, 18] 
    settings.settings(for: .code39).activeSymbolCounts = [10, 14] 

    for symbology in symbologies 
    { 
     settings.setSymbology(symbology, enabled: true) 
    } 

    let guiOptions = SBSGuiStyle.laser 

    // Create the barcode picker with the settings just created 
    let barcodePicker = SBSBarcodePicker(settings:settings) 

    // Add the barcode picker as a child view controller 
    addChildViewController(barcodePicker) 
    view.addSubview(barcodePicker.view) 
    barcodePicker.didMove(toParentViewController: self) 

    // Set the allowed interface orientations. The value UIInterfaceOrientationMaskAll is the 
    // default and is only shown here for completeness. 
    barcodePicker.allowedInterfaceOrientations = .portrait 


    // Set custom options 
    barcodePicker.overlayController.setVibrateEnabled(false) 
    barcodePicker.overlayController.guiStyle=guiOptions 


    let btn: UIButton = UIButton(frame: CGRect(x: 100, y: 400, width: 100, height: 50)) 
    btn.backgroundColor = UIColor.green 
    btn.setTitle("Click to scan", for: .normal) 
    btn.layer.cornerRadius = 10 
    btn.layer.masksToBounds = true 
    btn.addTarget(self, action: #selector(startManualScan), for: .touchUpInside) 

    barcodePicker.view.addSubview(btn) 

    // Set the delegate to receive scan event callbacks 
    barcodePicker.scanDelegate = self 
    barcodePicker.startScanning(inPausedState: true) 


} 

func startManualScan() 
{ 
    self.barcodePicker.startScanning() 
} 
+0

ist es StartScanning oder startScanning? – KKRocks

+0

startScanning, die oben auch in der Methode funktioniert jedoch nicht in dem Button-Aktion – Bubu

+0

self.barcodePicker ausgelöst werden, in dem erklärt? – KKRocks

Antwort

0

Versuchen:

Klasse scanViewController: UIViewController {

let barcodePicker = SBSBarcodePicker // declare here 

override func viewDidLoad() 
{ 
    super.viewDidLoad() 
    setupManualScanner() 
} 

func setupManualScanner() { 

    // Scandit Barcode Scanner Integration 
    // The following method calls illustrate how the Scandit Barcode Scanner can be integrated 
    // into your app. 

    // Create the scan settings and enabling some symbologies 
    let settings = SBSScanSettings.default() 

    let symbologies: Set<SBSSymbology> = [.code39, .code128] 
    settings.settings(for: .code128).activeSymbolCounts = [11,15,16,17, 18] 
    settings.settings(for: .code39).activeSymbolCounts = [10, 14] 

    for symbology in symbologies 
    { 
     settings.setSymbology(symbology, enabled: true) 
    } 

    let guiOptions = SBSGuiStyle.laser 

    // Create the barcode picker with the settings just created 
    barcodePicker = SBSBarcodePicker(settings:settings) // made change here 

    //continue your code 
} 


func startManualScan() 
{ 
    barcodePicker.startScanning() 
} 
+0

Arbeitete! Vielen Dank. Mit Zugabe() -> lassen barcodePicker = SBSBarcodePicker() // erklären hier – Bubu

+0

Willkommen .. @ Bubu – KKRocks

+0

akzeptiert Greatly – Bubu