swift - 带有 Xib 错误的 UItableView 部分标题视图 - Swift
问题描述
我尝试使用 Xib 文件实现部分标题。我创建了一个 Xib 视图并参加 UITableViewHeaderFooterView 到这个视图。当我运行 App 时,它给了我没有任何描述的错误。问题出在哪里 ?
提前致谢。
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 斯威夫特 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
}
我对其进行了测试:(如果您需要更多帮助,请告诉我将整个项目发送给您)
推荐阅读
- discord - discord.py Dsiplay 公会的图标使用 icon_url
- bash - 如何编写将作为 cron 作业工作的 mv 命令
- node.js - 如何通过 pm2 将 nodejs 部署到不同的主机?
- node.js - axios:错误:客户端网络套接字在建立安全 TLS 连接之前已断开连接
- python - 我正在尝试在不同对象的方法中调用对象
- javascript - 使用 typeORM Select Query Builder 时如何格式化日期?
- python - 如何修复pygame中的碰撞
- react-native - React Native 使用原生语音输入设置 TextInput 默认值
- vb.net - 无法添加对“Quartz.dll”的引用。项目中已存在对组件“Quartz”的引用
- json - 为什么此 JSON 响应中包含数据类型?