【发布时间】:2015-11-02 21:40:27
【问题描述】:
我有一个子类为 PFQueryTableViewController 的 TableView,我想知道如何从 Parse 检索用户发布的清单。我在接收用户数据和显示我的代码时遇到问题。我需要在我的 queryForTable 中编辑什么内容、更改解析或更改我的代码吗?
这是我的 ProfileViewController:
import UIKit
import Parse
import ParseUI
class ProfileViewController: PFQueryTableViewController{
var profilePosts:NSMutableArray! = NSMutableArray()
override init(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.parseClassName = "Test"
self.textKey = "postMessage"
self.pullToRefreshEnabled = true
self.objectsPerPage = 200
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func queryForTable() -> PFQuery {
let query = PFQuery(className: "Test")
query.whereKey("username", equalTo: PFUser.currentUser()!)
query.limit = 200;
return query
}
// MARK: - Table view data source
override func objectAtIndexPath(indexPath: NSIndexPath!) -> PFObject? {
var obj : PFObject? = nil
if(indexPath.row < self.objects!.count){
obj = self.objects![indexPath.row] as? PFObject
}
return obj
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return profilePosts.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath?, object:PFObject!) -> PFTableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("PCell", forIndexPath: indexPath!) as! ProfileCell
if let profilePost : PFObject = self.profilePosts.objectAtIndex(indexPath!.row) as! PFObject {
cell.NameProfile.text = object["account"] as? String
cell.messageProfile.text = object["postMessage"] as? String
let dateUpdated = object.createdAt! as NSDate
let dateFormat = NSDateFormatter()
dateFormat.dateFormat = "MMM d, h:mm a"
cell.timeProfile.text = NSString(format: "%@", dateFormat.stringFromDate(dateUpdated)) as String
cell.messageProfile.numberOfLines = 0
let likeScore = object[("count")] as! Int
cell.likeScoreProfile.text = "\(likeScore)"
let replyscore = object["replies"] as! Int
cell.replyScoreProfile.text = "\(replyscore) replies"
cell.messageProfile.text = profilePost.objectForKey("postMessage") as? String
if let profilePic = object["profilePhoto"] as? PFFile {
let imageView = cell.profilePhoto as PFImageView
imageView.image = UIImage(named: "profileImg")
imageView.file = profilePic
imageView.loadInBackground(nil)
}
return cell
}
【问题讨论】:
标签: ios swift parse-platform pfquery