我有UICollectionView
UIRefreshControl
。 UIRefreshControl
运行查询以从Parse.com获取对象。当我执行刷新"拉下"它会导致应用崩溃并显示以下消息:
fatal error: Cannot index empty buffer
然而,当我按下按钮或在ViewDidLoad
中运行相同的刷新代码时,它不会崩溃并根据需要执行查询。这是否意味着拖动而不是刷新代码有问题?
以下是刷新代码(与self.refreshControl.endRefreshing()
的定位有关吗?)
func refresh(sender:AnyObject)
{
println("Refresh")
self.orderedIdArray = []
self.idArray = []
self.organizerNameArray = []
self.categoryNameArray = []
self.classNameArray = []
var query = PFQuery(className:"Rides")
query.orderByAscending("date")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
// The find succeeded.
NSLog("Successfully retrieved \(objects.count) scores.")
// Do something with the found objects
for object in objects {
NSLog("%@", object.objectId)
var testId = object.objectId
println(testId)
self.orderedIdArray.append(testId)
var query = PFQuery(className:"Rides")
query.getObjectInBackgroundWithId(testId) {
(gameScore: PFObject!, error: NSError!) -> Void in
if error == nil {
NSLog("%@", gameScore)
//Gets the Values from Parse.com
self.organizerNameString = gameScore["organizer"] as String
self.categoryNameString = gameScore["category"] as String
self.classNameString = gameScore["class"] as String
self.organizerNameArray.append(self.organizerNameString)
self.categoryNameArray.append(self.categoryNameString)
self.classNameArray.append(self.classNameString)
self.idArray.append(object.objectId)
NSLog("%@", self.idArray)
} else {
println("Do not add to the array")
}
}
} else {
NSLog("%@", error)
}
self.collectionView?.reloadData()
}
}
} else {
// Log details of the failure
NSLog("Error: %@ %@", error, error.userInfo!)
}
self.refreshControl.endRefreshing()
NSLog("Ordered: %@", self.orderedIdArray)
}
println("Completed the query")
}