【发布时间】:2017-01-23 18:31:10
【问题描述】:
我有一个使用xib 文件构建的自定义视图。在这个自定义视图中,有一个UIView,我想在其中添加一个静态UITableView 作为子视图。此处显示的UITableView 出现在storyboard 上,并与UITableViewController 相关联。我做了以下事情:
let vc = (UIStoryboard(name: "Main", bundle: nil))
.instantiateViewControllerWithIdentifier("tableController") as! TableController
vc.loadViewIfNeeded()
table = vc.table // this is an outlet, I'm sure it is not nil
table.delegate = vc
table.dataSource = vc
table.backgroundColor = UIColor.greenColor()
containerView.addSubview(table)
我可以在自定义视图中看到绿色背景,但表格单元格没有显示
我知道表格的出口不是零,因为在调试时,如果我使用控制台下方的Quick Look 图标检查table 变量,我可以看到表格。
更新
我意识到我的方法并不好。
通过使我的视图成为UITableViewDataSource 和UITableViewDelegate 的子视图并以编程方式创建UITable 和必需的TableViewCell,我实现了我想要的结果。大量的代码!
【问题讨论】:
标签: swift uitableview uiview xib subview