简体   繁体   English

iOS 当我从 iOS 设置屏幕更改文本大小时,App UILabel 崩溃

[英]iOS App UILabel crashed when I change text size from iOS Settings Screen

I have我有

@IBOutlet weak var onlineStatusLabel: UILabel! 

declared in TableViewCell Class My table view use static cells.在 TableViewCell Class 中声明我的表视图使用 static 个单元格。 When I inside the app everything is ok, once I change text size setting in iOS setting screen and come back to my app, app crashes with this error:当我进入应用程序时一切正常,一旦我在 iOS 设置屏幕中更改文本大小设置并返回到我的应用程序,应用程序就会崩溃并出现此错误:

appName/TableVC.swift:47: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value appName/TableVC.swift:47:致命错误:在隐式展开可选值时意外发现 nil

This is what I call from my TableVC:这是我从我的 TableVC 中调用的:

import UIKit

class TableVC: UITableViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
      //  super.tableView(tableView, willDisplay: cell, forRowAt: indexPath)
        guard let cell = cell as? CustomTableViewCell else { return }
        cell.onlineStatusLabel.textColor = .red // app crash here, this means that onlineStatusLabel is nil, but how???
        cell.onlineStatusLabel.text = "Text"
    }
}

CellView:细胞视图:

import UIKit

class CustomTableViewCell: UITableViewCell {
    @IBOutlet weak var onlineStatusLabel: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

Image with code for TableVC带有 TableVC 代码的图像

Image with code for Cell带有 Cell 代码的图像

Storyboard configuration Storyboard配置

Storyboard cell configuration Storyboard 小区配置

How it can be nil?怎么可能是零呢? How size change can react on UILabel?尺寸变化如何影响 UILabel? Can you please suggest?你能建议一下吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM