我有一个tableView从php json中使用Alamofire加载数据,它在tableView上完美地加载了数据,现在我想将数据传递到第二个viewController以显示更多详细信息,但是我遇到了这个错误:无法在范围内找到数据。
func getUsers() {
AF.request(SiteUrl).validate().responseJSON { response in
switch response.result {
case .success:
print("Validation Successful)")
if let json = response.data {
do{
let jsonData = try JSON(data: json)
self.data = jsonData.arrayValue
self.tableView.reloadData() // we are already on the main thread
//print("DATA PARSED: \(jsonData)")
}
catch {
print("JSON Error", error)
}
}
case .failure(let error):
print(error)
}
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let customCell = tableView.dequeueReusableCell(withIdentifier: TableViewCell.identifier, for: indexPath) as! TableViewCell
let item = data[indexPath.row]
customCell.AdTitle?.text = item["title"].string
customCell.AdDate?.text = item["time"].string
let imageUrl = item["document"].string
let url = NSURL(string:("https://qateef-ads.co/uploads/" + imageUrl!))
customCell.AdImage.sd_setImage(with: url as URL?, placeholderImage: UIImage(named: "placeholder.png"))
return customCell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = storyboard?.instantiateViewController(withIdentifier: "DetailsViewController") as? DetailsViewController
self.navigationController?.pushViewController(vc!, animated: true)
vc?.imageView = UIImage(named: url)
vc?.AdTitle = item["title"].string
}
我如何将数据从一个视图传递到另一个视图?