很难将parse.com查询中的两个以上对象拖入PFTableViewController。以下代码适用于查询和显示单元格中的两个项目。但是,在成功segueing的详细视图中,我可以传递两个对象中的一个来显示在原始单元格中,但我希望该类的所有对象都显示在详细视图控制器中。问题是我无法弄清楚如何查询或(可能是正确的术语)来自类的两个以上的对象将它们传递给detailViewController。 我的班级名字是" event" 对象我想详细介绍View:" category" (成功) 而且:" createdAt" "评价"和"持续时间(int)"
我的PFTableViewController:
import UIKit; import Parse
class UserRecordsTableViewController: PFQueryTableViewController {
// Initialise the PFQueryTable tableview
override init!(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// Configure the PFQueryTableView
self.parseClassName = "Event"
self.textKey = "category"
self.title = "createdAt"
self.pullToRefreshEnabled = true
self.paginationEnabled = false
}
// Define the query that will provide the data for the table view
override func queryForTable() -> PFQuery! {
var query = PFQuery(className: "event")
query.orderByAscending("createdAt")
query.whereKey("user", equalTo: PFUser.currentUser())
return query
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject) -> PFTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UserRecordsTableViewCell!
if cell == nil {
cell = UserRecordsTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
}
var dateUpdated = object.createdAt as NSDate
var dateFormat = NSDateFormatter()
dateFormat.dateFormat = "EEE, MMM d, h:mm a"
cell.catDate.text = NSString(format: "%@", dateFormat.stringFromDate(dateUpdated))
cell.catTitle.text = object["category"] as String!
return cell
}
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using [segue destinationViewController].
var detailScene = segue.destinationViewController as DetailUserRecordsViewController
// Pass the selected object to the destination view controller.
if let indexPath = self.tableView.indexPathForSelectedRow() {
let row = Int(indexPath.row)
detailScene.currentObject = objects[row] as? PFObject
}
}
}
我的详细信息视图控制器
import UIKit
import Parse
// Container to store the view table selected object
var currentObject : PFObject?
class DetailUserRecordsViewController: UIViewController {
// Container to store the view table selected object
var currentObject : PFObject?
@IBOutlet weak var eventTextAlter: UITextField!
@IBOutlet weak var dateTextAlter: UITextField!
@IBOutlet weak var durationTextAlter: UITextField!
@IBOutlet weak var commentTextAlter: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// Unwrap the current object object
if let object = currentObject? {
/*var dateUpdated = object.createdAt as NSDate
var dateFormat = NSDateFormatter()
dateFormat.dateFormat = "EEE, MMM d, h:mm a"
var newDuration = object["duration"] as String*/
eventTextAlter.text = object["category"] as String
//dateTextAlter.text = NSString(format: "%@", dateFormat.stringFromDate(dateUpdated))
//durationTextAlter.text = newDuration as String
//commentTextAlter.text = object["comments"] as String
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/