我一直在关注Youtube的教程,它可以帮助您使用 Parse 作为后端服务来创建像Twitter这样的应用。到目前为止,我能够在Parse中向类添加内容,但是我要么无法检索它们,要么在我的表视图中显示它们。
我相信这是我的错误所在:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:messageTableViewCell = tableView!.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath!) as messageTableViewCell
let sweet:PFObject = self.timelineData.objectAtIndex(indexPath!.row) as PFObject
cell.messageTextView.alpha = 0
cell.timestampLabel.alpha = 0
cell.usernameLabel.alpha = 0
cell.messageTextView.text = sweet.objectForKey("content") as String
var dataFormatter:NSDateFormatter = NSDateFormatter()
dataFormatter.dateFormat = "yyyy-MM-dd HH:mm"
cell.timestampLabel.text = dataFormatter.stringFromDate(sweet.createdAt)
var findSweeter:PFQuery = PFUser.query()
findSweeter.whereKey("objectId", equalTo: sweet.objectForKey("username").objectId)
findSweeter.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]!, error:NSError!)->Void in
if error == nil{
let user:PFUser = (objects as NSArray).lastObject as PFUser
cell.usernameLabel.text = user.username
UIView.animateWithDuration(0.5, animations: {
cell.messageTextView.alpha = 1
cell.timestampLabel.alpha = 1
cell.usernameLabel.alpha = 1
})
}
}
return cell
}
如果你能帮我解决这个问题,我会非常感激,也请尽量详细。
错误可能也在这里,我完全丢失了所以我也会发布这个错误!
func loadData(){ timelineData.removeAllObjects()
var findTimelineData:PFQuery = PFQuery(className: "Messages")
findTimelineData.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]!, error:NSError!)->Void in
if error == nil{
for object in objects{
let message:PFObject = object as PFObject
self.timelineData.addObject(message)
}
let array:NSArray = self.timelineData.reverseObjectEnumerator().allObjects
self.timelineData = NSMutableArray(array: array)
self.tableView.reloadData()
}
}
}