这是我的代码:
我正在使用NSMutableArray:
var BusinessNamesArray: NSMutableArray = []
在我的viewDidLoad()
中ref.queryOrderedByChild("Category").queryEqualToValue(titlestring)
.observeEventType(.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["BusinessName"] as? String
{
mainDict.setObject(metname, forKey: "BusinessName")
}
if let metname = dictnew["ShortDescription"] as? String
{
mainDict.setObject(metname, forKey: "ShortDescription")
}
}
self.BusinessNamesArray.addObject(mainDict)
}
print("arrayt is \(self.BusinessNamesArray)")
}
self.tableView.reloadData()
})
}
表视图数据源:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("BusinessCell", forIndexPath: indexPath)
if let name = BusinessNamesArray[indexPath.row] as? NSMutableDictionary{
cell.textLabel?.text = name["BusinessName"] as? String
cell.detailTextLabel?.text = name["ShortDescription"] as? String
}
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
return cell
}
override 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! DetailsViewController
if let name = self.BusinessNamesArray[indexPath.row] as? NSMutableDictionary{
detailsViewController.self.strUserid = name["userid"] as? String
}
self.navigationController?.pushViewController(detailsViewController, animated: true)
}
}
这是构建它时的样子: Click here
我正在尝试以编程方式将searchBar添加到UITableView,我遵循了本教程here,它在本教程中的入门项目上工作,但是当我在我的项目上尝试它时:在这一行{ {1}}它给了我这个错误:实例成员'BusinessNamesArray'不能用于'SpecificCategoryTablrVC'类型
任何人都知道问题是什么,以及如何解决?