【发布时间】:2020-01-08 23:56:23
【问题描述】:
当我尝试修改单元格子视图时,UITableViewCell 因“在隐式展开可选值时意外发现 nil”而崩溃。
注册tableView单元格
self.tableView.register(TravelTypeTableViewCell.self, forCellReuseIdentifier: "TravelCell")
表格视图方法
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 224
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TravelCell", for: indexPath) as! TravelTypeTableViewCell
cell.travelTypeSegment.selectedSegmentIndex = 0
return cell
}
TableViewcell 类
class TravelTypeTableViewCell: UITableViewCell {
@IBOutlet var travelTypeSegment: UISegmentedControl!
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
}
}
故事板图片
【问题讨论】:
-
您不得注册原型单元。
travelTypeSegment是否连接在单元格中?
标签: ios swift uitableview