我尝试使用 Xib 文件实现节标题。我创建一个 Xib View 并将 UITableViewHeaderFooterView 添加到该 View 。当我运行该应用程序时,它给我错误,没有任何描述。问题出在哪里?
提前致谢。
tableView.register(UINib(nibName: "EventViewCell", bundle: nil), forCellReuseIdentifier: "EventViewCell")
tableView.register(UINib(nibName: "EventCellSectionHeader", bundle: nil), forHeaderFooterViewReuseIdentifier: "EventCellSectionHeader")
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = tableView.dequeueReusableHeaderFooterView(withIdentifier: "EventCellSectionHeader") as! EventCellSectionHeader
cell.headerName.text = "aa"
return cell
}
class EventCellSectionHeader: UITableViewHeaderFooterView {
@IBOutlet var headerName: UILabel!
}
libc++abi.dylib:以 NSException 类型的未捕获异常终止
最佳答案
Xcode 10 SWIFT 4
按如下方式实现 viewForHeaderInSection:
//EventCellHeader is the name of your xib file. (EventCellHeader.xib)
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = Bundle.main.loadNibNamed("EventCellHeader", owner: self, options: nil)?.last as! EventCellSectionHeader
header.headerName.text = "aa"
return header
}
我测试了它:(如果您需要更多帮助,请告诉我将整个项目发送给您)
关于swift - 带有 Xib 错误的 UItableView 部分标题 View - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52720146/