繁体   English   中英

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

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

我有

@IBOutlet weak var onlineStatusLabel: UILabel! 

在 TableViewCell Class 中声明我的表视图使用 static 个单元格。 当我进入应用程序时一切正常,一旦我在 iOS 设置屏幕中更改文本大小设置并返回到我的应用程序,应用程序就会崩溃并出现此错误:

appName/TableVC.swift:47:致命错误:在隐式展开可选值时意外发现 nil

这是我从我的 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"
    }
}

细胞视图:

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
    }

}

带有 TableVC 代码的图像

带有 Cell 代码的图像

Storyboard配置

Storyboard 小区配置

怎么可能是零呢? 尺寸变化如何影响 UILabel? 你能建议一下吗?

暂无
暂无

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

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