【发布时间】:2018-12-06 07:32:08
【问题描述】:
我是编程新手,目前正在开发类似应用程序的新闻源。我有一个正常的表格视图并运行良好,但现在想尝试使用服装单元格类型。所以我创建了一个,并认为以通常的方式连接标签会非常好,但我错了。所以我想知道如何让我的文本标签连接到我的视图控制器,这样我就可以使用我的自定义单元格。
class ViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var newsfeedTableView: UITableView!
var ref: DatabaseReference!
var posts = [String]()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (posts.count)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: "cell")
//here is where I need the custom label to get the posts
cell.textLabel?.text = posts[indexPath.row]
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 18.0)
return cell
}
}
【问题讨论】:
-
您是否对
UITableViewCell进行了子类化并将该类分配给情节提要中的原型单元格? -
可能与您的情况相符stackoverflow.com/a/25545185/6202732
标签: swift uitableview