[英]Multiple PFObjects In Parse Query and PFTableViewController
使用自定義PFTableViewCell和PFQueryTableViewController顯示多個更新的標簽時遇到問題。 聲明的第一個textKey或對象在運行后確實顯示,但其他標簽顯示為空白。 您還會注意到,截至目前,日期也未到,但我一次正在解決一個問題。 我想我需要聲明另一個textKey類,但是已經嘗試將其添加到PFQueryTableViewController.h並啟動但那沒用。 這是我的TableViewController:
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.textKey = "duration"
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("category")
return query
}
//override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
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")
}
// Extract values from the PFObject to display in the table cell
cell.durationEventLabel.text = object["duration"] as? String
cell.dateEventLabel.text = object["category"] as? String
// Date for cell subtitle
/*var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let dateForText = object["createdAt"] as NSDate
cell.dateEventLabel.text = dateFormatter.stringFromDate(dateForText)*/
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 YourDetailViewController
// 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
class UserRecordsTableViewCell: PFTableViewCell {
@IBOutlet weak var dateEventLabel: UILabel!
@IBOutlet weak var catEventLabel: UILabel!
@IBOutlet weak var durationEventLabel: UILabel!
}
這是我的PFQueryTableViewController.h中的一個選擇
@property (nonatomic, strong) NSString *textKey;
我已決定實現所需外觀的最佳方法是使用解析框架提供的PFTableViewCell,並且僅顯示兩個項目。 主類別和日期為副標題 。 這與創建一個自定義單元格相反,該自定義單元格與文本和圖像標簽配合使用很好,但與兩個文本鍵配合使用卻效果不好。 遵循了本教程,很棒:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.