ios - 从自定义类更新 UIProgressView 出现错误可选展开

标签 ios swift

我对此感到疯狂......希望你能帮助我。 我想做的是从我的名为“myPDF”的自定义类更新 UIProgressView(有一种将 PDF 转换为图形的方法)。

UIProgressView 应显示转换的进度... 但我收到一个 fatal error :

“解包可选值时意外发现 nil”

这是我的自定义类:

protocol DataEnteredDelegate {
    func loadingInformation (PDFprogress: Float, TextLabel: String)
}

class myPDF {

    var delegate: DataEnteredDelegate?

    var imageArray:[UIImage] = []
    var PDFname: String
    var progressPDF: Float = 0
        {
        didSet{
                let textconvert = String(progressPDF)
                delegate!.loadingInformation(progressPDF,TextLabel: textconvert)
                print("value from progressPDF: \(progressPDF)")
            }
        }

这就是我的 viewController.swift:

class initViewController: UIViewController, DataEnteredDelegate{

    @IBOutlet var progressBar: UIProgressView!
    @IBOutlet var startButton: UIButton!
    @IBOutlet var textLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        loadingInformation(0, TextLabel: "0")  
    }

    func loadingInformation (PDFprogress: Float, TextLabel: String) {
        progressBar.progress = PDFprogress
        textLabel.text = TextLabel
        print(PDFprogress)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

最佳答案

不清楚,你在哪里得到这个错误,但检查你的“隐式解开的选项”——带有感叹号的变量。 一个或多个未初始化。

关于ios - 从自定义类更新 UIProgressView 出现错误可选展开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35915529/

相关文章:

ios - 为什么实例变量在闭包内具有不同的值?

ios - Xcode:在框架中使用静态库?

iphone - Facebook IOS 应用内登录对话框不 Conceal 密码

objective-c - applicationWillTerminate 不会在强制退出 iOS 应用程序时被调用

ios - UIPasteboard – 设置复制的文本过期

swift - 如果 PromiseKit promise 已经在运行,那么返回待定 PromiseKit promise 的最佳 Swift 模式是什么?

ios - 在 iOS/objective-C 中检测下划线和插入字符

ios - 没有 UINavigationController 的 UINavigationBar

ios - 导航栏 Swift 中的文本颜色

swift 4 Codable - 如果有字符串或字典如何解码?