I have
@IBOutlet weak var onlineStatusLabel: UILabel!
declared in TableViewCell Class My table view use static cells. 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:
appName/TableVC.swift:47: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
This is what I call from my 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
}
}
How it can be nil? How size change can react on UILabel? Can you please suggest?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.