【问题标题】:How to go to new viewcontroller after scanning a QR code?扫描二维码后如何进入新的viewcontroller?
【发布时间】:2017-01-12 15:40:40
【问题描述】:

我现在尝试了好几个小时来尝试让我的应用程序正常工作。问题是应用程序检测到二维码后,它不会显示新的视图控制器。它将在新的视图控制器中对日志执行一个简单的打印语句,但应用程序中不存在新的视图控制器。我已经在 Stackoverflow 上尝试了许多解决方案,但在这种特定情况下似乎没有任何帮助。

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")
}

日志确实显示了打印语句“Hi”,但应用程序没有转到 infoViewController。情节提要中还包含 infoViewController,并选择了类 infoViewController。

目前有没有我遗漏的细节?

问候

【问题讨论】:

  • captureoutput函数中的self是什么对象?
  • 你用的是故事板还是xib
  • 如果你想展示 ViewController 它应该来自其他 ViewController。
  • 嗨,我正在使用故事板
  • 是否进入 ViewWillAppear 方法?此外,您应该将断点放入 ViewDidLoad 并检查值。

标签: ios swift uiviewcontroller swift3


【解决方案1】:

首先,您必须在storyboard 上选择infoViewController,然后在身份检查器中,您必须像这样添加Storyboard ID

那么你必须像这样展示infoViewController

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

【讨论】:

  • 不幸的是不工作,它也不会进入viewDidLoad函数:'(
  • 您是否将情节提要中的infoViewController 类设置为ViewController
猜你喜欢
  • 2022-07-22
  • 1970-01-01
  • 2019-06-12
  • 1970-01-01
  • 2017-12-22
  • 1970-01-01
  • 1970-01-01
  • 2022-07-20
  • 2021-10-08
相关资源
最近更新 更多