我在尝试在tableview中显示图像时出错。 它正在显示文本,但没有显示任何图像。“类型”值'没有下标成员“在Swift中出错
class ViewController: UITableViewController {
var ref: FIRDatabaseReference!
var refHandle: UInt!
var valueList = [Values]()
override func viewDidLoad() {
super.viewDidLoad()
ref = FIRDatabase.database().reference()
fetchFirebaseData()
}
func fetchFirebaseData() {
refHandle = ref.child("SwiftJson").observe(.childAdded, with:
{(snapshot) in
if let dictionary = snapshot.value as? [String : AnyObject] {
print(dictionary)
let value = Values() as AnyObject
value.setValuesForKeys(dictionary)
self.valueList.append(value as! Values)
self.tableView.reloadData()
}
})
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return valueList.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! FTableViewCell
let value = valueList[indexPath.row]
cell.fTitle.text = value.title
let imageUrlString = valueList[indexPath.row]["image"] as! String
let imageURL = NSURL(string: imageUrlString)
let imageData = NSData(contentsOf: imageURL as! URL)
cell.fImage.image = UIImage(data: imageData as! Data)
return cell
}
}
在这里,我解析来自Firebase数据库的数据,并试图在tableview上显示它。
您是否尝试过搜索其中的100个问题之一? – Alexander
究竟哪一行导致错误? – rmaddy
以前这已被问及过多次回答! – matt