1
我从下面的代码中收到此错误。我已阅读并尝试了类似问题的一些解决方案,但他们还没有很好地工作。任何帮助将非常感激。无法在属性初始值设定项中使用实例成员'parseData'
class allTripsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let list = parseData()
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return list.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
cell.textLabel?.text = list[indexPath.row]
return cell
}
func parseData() -> [String] {
//get some json data and put it into the array
return delays
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
如果它是让列表= [“牛奶”,“蜂蜜”]等,这完美呈现在桌上。但我需要它使用parseData中的数组。
感谢您的回复!不,我没有尝试过这样做。只有一个问题,它说“模糊引用成员'tableView(_:numberOfRowsInSection :)'” – Dharyin
检查您的代码。也许你已经添加了该方法两次 – Woof
它绝对只有一次。 我在想这可能是关于如何有两个函数称为tableView,但他们采取不同的参数... – Dharyin