我试图从解析中获取数据并将其呈现在表格视图中。我无法编译代码,因为这是一个错误。
这是我的代码:
import UIKit
import Parse
class EventsTableViewController: UITableViewController {
// Array to store event timeline objects from parse
var eventtimelineData:NSMutableArray = NSMutableArray()
override func viewDidAppear(animated: Bool) {
self.loadData()
}
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func loadData(){
// first remove the contents from the array
eventtimelineData.removeAllObjects()
var findTimelineData:PFQuery = PFQuery(className: "Events")
findTimelineData.findObjectsInBackgroundWithBlock{
(objects: [AnyObject]!, error: NSError!) -> Void in
// if query doesn't return any error
if !error{
for object:PFObject! in objects{
self.timelineData.addObject(object)
}
let array:NSArray = self.timelineData.reverseObjectEnumerator().allObjects
self.timelineData = array as NSMutableArray
self.tableView.reloadData()
}
}
}
这是我得到的错误:
你可以帮我解决这个问题吗?感谢。([AnyObject] !, NSError!) - >虚空'不能转换为' PFArrayResultBlock?
答案 0 :(得分:0)
想出来。 Parse更新了他们的查询语法。这有效。
@IBAction func loadData(){
// first remove the contents from the array
eventtimelineData.removeAllObjects()
let query = PFQuery(className:"Events")
query.whereKey("CreatedBy", equalTo:PFUser.currentUser()!)
query.findObjectsInBackgroundWithBlock {
(objects, error) -> Void in
if error == nil {
// The find succeeded.
print("Successfully retrieved \(objects!.count) scores.")
// Do something with the found objects
if let objects = objects as? [PFObject] {
for object in objects {
self.eventtimelineData.addObject(object)
print(object.objectId)
print(object.description)
}
let array:NSArray = self.eventtimelineData.reverseObjectEnumerator().allObjects
self.eventtimelineData = array.mutableCopy() as! NSMutableArray
self.tableView.reloadData()
}
} else {
// Log details of the failure
print("Done")
print("Error: \(error!) \(error!.userInfo)")
}
}
}