我現在試了好幾個小時試圖讓我的應用程序工作。問題是,在應用程序檢測到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。
有沒有我目前缺少的細節?
問候
什麼樣的對象是自己在捕獲放功能? – Lefteris
你使用stroryboard或xib –
如果你想呈現ViewController,它應該來自其他ViewController。 –