【问题标题】:How to access ViewController's class functions from another class?如何从另一个类访问 ViewController 的类函数?
【发布时间】:2020-03-05 15:10:34
【问题描述】:

我在 ViewController 类中有这个功能:

func detect(image: CIImage) {
    guard let model = try? VNCoreMLModel(for: Resnet50().model)
        else {
            fatalError("Loading CoreML Model Failed.")
    }

    let request = VNCoreMLRequest(model: model) {
        (request, error) in
        guard let result = request.results as? [VNClassificationObservation]
            else {
                fatalError("Model failed to process image.")
        }
        print(result.first?.identifier as Any)
        self.imageLabel.text = result.first?.identifier
    }

    let handler = VNImageRequestHandler(ciImage: image)
    do {
        try handler.perform([request])
    } catch {
        print(error)
    }
}

我正在尝试使用 result.first?.identifier 在另一个名为 SecondViewController 的类中执行类似的操作:

if(result.first?.identifier == "flowers") {
    self.infoLabel.text = "info about flowers"
}

但我不知道如何访问其他类中的函数。我刚开始用 Swift 编码。

【问题讨论】:

标签: swift segue mlmodel


【解决方案1】:

我找到了a link,它帮助我解决了我遇到的这个问题,如果将来有人需要,我会在这里分享。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-11
    • 2019-04-03
    相关资源
    最近更新 更多