2017-09-28 17 views
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中的数组。

回答

0

你有没有尝试使列表数组分配为空数组,然后通过解析值填充它?

var list = [String]() 

override func viewDidLoad(){ 
super.viewDidLoad() 

list = parseData() 

tableView.reloadData() 

} 

此外,从主队列中的parseData获取值非常重要。如果您要异步获取parseData,则必须使用parseData内的完成块来返回主队列中的值。 让我知道你是否需要更多的细节

+0

感谢您的回复!不,我没有尝试过这样做。只有一个问题,它说“模糊引用成员'tableView(_:numberOfRowsInSection :)'” – Dharyin

+0

检查您的代码。也许你已经添加了该方法两次 – Woof

+0

它绝对只有一次。 我在想这可能是关于如何有两个函数称为tableView,但他们采取不同的参数... – Dharyin

相关问题