簡體   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