我从下面的代码中得到这个错误。我已经阅读并尝试了一些类似问题的解决方案,但它们并没有奏效。任何帮助将不胜感激。
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()
}
}
如果 let list = ["Milk", "Honey"] 等,这很好用。完美地呈现在 table 上。但我需要它来使用 parseData 中的数组。
最佳答案
您是否尝试过将列表数组分配为空数组,然后用解析后的值填充它?
var list = [String]()
override func viewDidLoad(){
super.viewDidLoad()
list = parseData()
tableView.reloadData()
}
从主队列中的 parseData 获取值也很重要。如果您异步获取 parseData,则必须在 parseData 中使用完成 block 来返回主队列中的值。 如果您需要更多详细信息,请告诉我
关于ios - 无法在属性初始值设定项中使用实例成员 'parseData',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46461650/