我确实通过简单的格式制作了一个包含所有列表值的数组,并显示如下项目列表:
var namesArray : NSMutableArray = []
它是viewDidLaod 方法如下所示:
override func viewDidLoad() {
super.viewDidLoad()
ref.queryOrderedByChild("Picker").queryEqualToValue("Makkah")
.observeSingleEventOfType(.Value, withBlock: { snapshot in
if let dict = snapshot.value as? NSMutableDictionary{
print("print \(dict)")
for (key,value) in dict {
let mainDict = NSMutableDictionary()
mainDict.setObject(key, forKey: "userid")
if let dictnew = value as? NSMutableDictionary{
if let metname = dictnew["name"] as? String
{
mainDict.setObject(metname, forKey: "name")
}
if let metname = dictnew["Picker"] as? String
{
mainDict.setObject(metname, forKey: "Picker")
}
if let metname = dictnew["details"] as? String
{
mainDict.setObject(metname, forKey: "details")
}
if let metname = dictnew["email"] as? String
{
mainDict.setObject(metname, forKey: "email")
}
if let metname = dictnew["provider"] as? String
{
mainDict.setObject(metname, forKey: "provider")
}
}
self.namesArray.addObject(mainDict)
}
print("arrayt is \(self.namesArray)")
}
self.CookingTableView.reloadData()
})
}
其数组Show在TableView的cellForRowAtIndexPath中必须有如下代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.CookingTableView.dequeueReusableCellWithIdentifier("CookingCell", forIndexPath: indexPath) as! CookingTableViewCell
if let name = namesArray[indexPath.row] as? NSMutableDictionary{
cell.BusinessNameLabel?.text = name["name"] as? String
cell.DescriptionLabel?.text = name["details"] as? String
}
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
return cell
}
现在上市的事情已经完成了。让我们在didSelectRowAtIndexPath 方法上显示它的详细信息:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
dispatch_async(dispatch_get_main_queue()) { [unowned self] in
let DetailsViewController = self.storyboard!.instantiateViewControllerWithIdentifier("ProjectDetailsViewController") as! ProjectDetailsViewController
if let name = self.namesArray[indexPath.row] as? NSMutableDictionary{
DetailsViewController.self.strUserid = name["userid"] as? String
}
self.navigationController?.pushViewController(DetailsViewController, animated: true)
}
}
在上面的 didSelect 方法中,我传递了 userID 唯一用户 ID 需要在 PushedViewController 中获取它的详细信息。您还可以将选定项目的墙字典发送到 nextviewController 但我在 nextViewController 中使用调用的 firebase 查询方法,因此 nextViewController 代码如下所示:
var strUserid : NSString!
它是 ViewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
print("idis \(self.strUserid)")
ref.childByAppendingPath(self.strUserid as String).observeEventType(.Value, withBlock: { snapshot in
if let dict = snapshot.value as? NSMutableDictionary{
print("dict is \(dict)")
if let name = dict["name"] as? String
{
self.Name.text = name
}
if let details = dict["details"] as? String
{
self.Details.text = details
}
if let email = dict["email"] as? String
{
self.Email.text = email
}
}
})
}
就是这样,希望您的问题能够得到解决。我用上面的方法做了这种方法。