Parse Query和PFTableViewController中的多个PFObject

时间:2015-03-16 00:27:51

标签: ios swift parse-platform

使用自定义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;

1 个答案:

答案 0 :(得分:0)

我已经决定了我想要的外观的最佳方法是使用parse框架提供的PFTableViewCell并且只显示两个项目。主要类别和日期为副标题。这与创建自定义单元格相反,后者适用于文本和图像标签,但不适用于两个文本键。 按照本教程进行操作非常棒:

https://medium.com/swift-programming/ios-swift-parse-com-tutorial-set-up-xcode-project-part-2-of-3-31a17d1c6581