今天重构代码的时候,打算提取一个UIView, UIView 的 Frame 没有动。直接把下面的代码放到了 override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
中
let headView = MLHeadFirstView(frame: CGRect(x: leftSpace_20, y: pageFlowView.bottom + 20, width: 200, height: 50))
headView.backgroundColor = UIColor.red
return headView
运行
报错
Fatal error: Unexpectedly found nil while unwrapping an Optional value
致命错误:解包可选值时意外发现nil
这是因为 在 给 MLHeadFirstView
的Frame
赋值的时候 pageFlowView.bottom
没有值。所以去掉即可。