2017-01-12 16 views
0

我現在試了好幾個小時試圖讓我的應用程序工作。問題是,在應用程序檢測到QR碼後,它不會顯示新的視圖控制器。它將在該新視圖控制器中執行一條簡單的打印語句,但該應用程序中不存在新的視圖控制器。我已經在Stackoverflow上嘗試了許多解決方案,但似乎沒有任何幫助解決這個問題。掃描QR碼後如何轉到新的viewcontroller?

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) { 
    captureSession.stopRunning() 

    if let metadataObject = metadataObjects.first { 
     let readableObject = metadataObject as! AVMetadataMachineReadableCodeObject; 

     AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate)) 
     found(code: readableObject.stringValue); 

    } 
    let vc = infoViewController() 
    self.present(vc, animated: true, completion: nil) 

我使用最後一行來指向應用程序掃描QR碼後應該去的新infoViewController。在infoViewController的代碼如下:

import UIKit 

class infoViewController: UIViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
     print("Hi") 
} 

日誌確實顯示print語句「嗨」,但應用程序不會去infoViewController。故事板中還有infoViewController,其中選擇了類infoViewController。

有沒有我目前缺少的細節?

問候

+0

什麼樣的對象是自己在捕獲放功能? – Lefteris

+0

你使用stroryboard或xib –

+0

如果你想呈現ViewController,它應該來自其他ViewController。 –

回答

0

首先你要選擇你的storyboardinfoViewController和身份檢查,你必須添加一個Storyboard ID這樣的:

enter image description here

然後,你必須出示infoViewController像這樣:

OperationQueue.main.addOperation { 
    let infoViewController = self.storyboard?.instantiateViewController(withIdentifier: "infoViewController" 
    self.present(infoViewController, animated: true) 
} 
+0

不幸的是,它不工作也不會進入viewDidLoad函數:'( – Jelleko

+0

您是否在故事板中將'infoViewController'類設置爲'ViewController'? – pableiros