我尝试了很多变化。另外,它工作正常并打印正确的值,但我想查询与用户ID匹配的项目。我尝试了很多东西,它返回的都是空白[]
。有人可以帮我吗?
在tableview上显示的项目应该是与其用户ID /用户名
匹配的项目var itemList = [String]()
var userid = [String]()
var names = [String]()
override func viewDidLoad() {
super.viewDidLoad()
let query = PFQuery(className:"reservedCust")
query.whereKey("item", containedIn: names)
query.findObjectsInBackgroundWithBlock {
(objects, error) -> Void in
if error == nil {
if let objects = objects {
for object in objects {
if let item = object["item"] as? String {
self.itemList.append((object["item"] as? String)!)
}
if let name = object["userid"] as? String {
self.names.append((object["userid"] as? String)!)
}
}
}
print(self.userid)
self.tableView.reloadData()
}else {
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return itemList.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.textLabel?.text = itemList[indexPath.row]
return cell
}