2019年5月22日 星期三

iOS swift 5: 關於 Segue Prepare to NavigationController


解決方案來源:
ios - Swift : prepareForSegue with navigation controller - Stack Overflow

class MainViewController: UIViewController
{
   /* Class Bluetooth CBCentralManager Control */
   var BleConnectDevice: TBleDeviceConnect! = nil
    override func prepare(for segue: UIStoryboardSegue, sender: Any?)
    {
     if( segue.identifier == "SegueOptions")
     {
      let destinationNavigationController = segue.destination as! UINavigationController
      let OptionsVc = destinationNavigationController.topViewController as! OptionsTableViewController
      OptionsVc.BleScannerDevice = self.BleScannerDevice
     }
    }
}

class OptionsTableViewController: UITableViewController, UITextFieldDelegate
{
    var BleScannerDevice: TBlueScannerDevice! = nil
    @IBAction func BtnBleOnClick(_ sender: Any)
    {
      DispatchQueue.main.async
      {
       self.BleScannerDevice.CentralManagerInit()
      }
    }
}

class TBleDeviceConnect: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
{
    var cCentralManager: CBCentralManager! = nil
    func CentralManagerInit()
    {
     cCentralManager = CBCentralManager.init(delegate: self, queue: nil, options: [CBCentralManagerOptionShowPowerAlertKey: true])
    }
}


沒有留言:

張貼留言