【发布时间】:2019-06-01 16:55:43
【问题描述】:
这已经让我绊倒了一段时间了。我正在尝试将列表出列到表视图中(嵌入在视图控制器中)。
class mainViewController: UIViewController {
var topicsE1: [Topic] = [
Topic(title: "Practice", startDate: "January 5, 2019"),
Topic(title: "Fundamentals", startDate: "January 6, 2019")]
扩展名:
extension mainViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "topicCellE1", for: indexPath)
cell.textLabel?.text = "\(topicsE1.title)" //Error message is here
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return topicsE1.count
}
}
该类在另一个文件中定义
class Topic {
var title: String
var startDate: String
init(title: String, startDate: String) {
self.title = title
self.startDate = startDate
}
}
扩展识别topicE1,但报错
“'[Topic]'类型的值没有成员'title'”
当代码如上时(topicsE1.title)。
【问题讨论】:
标签: ios swift uitableview class methods