【发布时间】:2016-04-13 15:11:32
【问题描述】:
这是 iOS 应用程序的仪表板:
{
"users" : {
"0b71693a-4f16-4759-acd6-706da1a466a0" : {
"Picker" : "Jubail",
"details" : "iOS second",
"name" : "Huda"
},
"16b13b1e-0025-4eee-a590-5bbacc52071c" : {
"Picker" : "Jeddah",
"details" : "Hellom from the Internet",
"name" : "Rania"
},
"394b6555-1838-4565-87ac-e423c3b89cf1" : {
"Picker" : "Jubail",
"details" : "",
"name" : "Marwa"
},
}
}
我正在尝试将选择器为 Jubail 的所有用户的名称检索到表格视图单元格中!
我是swift的初学者,我不知道该怎么做! 我试过了,这是我做的代码:
import UIKit
class CookingViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var BusinessName:[String: String] = [String:String]()
let ref = Firebase (url: "https://mariahfinaltest.firebaseio.com")
@IBOutlet weak var CookingTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
ref.queryOrderedByChild("Picker").queryEqualToValue("Riyadh")
.observeEventType(.Value, withBlock: { snapshot in
for child in snapshot.children {
self.BusinessName = child.value["name"] as! [String: String]
}
self.CookingTableView.reloadData()
})
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5 //It should not be 5 here! How Can I make it as long as cells?
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.CookingTableView.dequeueReusableCellWithIdentifier("CookingCell", forIndexPath: indexPath) as! CookingTableViewCell
var keys: Array = Array(self.BusinessName.keys)
cell.BusinessNameLabel.text = BusinessName[keys[indexPath.row]] as String!
return cell
}
}
我不断收到错误! 我不知道怎么了!
【问题讨论】:
标签: ios xcode swift firebase tableview