简体   繁体   English

UILabel不在UITableViewController的自定义原型单元中更新

[英]UILabels not updating in custom prototype cell of UITableViewController

Have tried several variations and watched different tutorials but cannot get my custom prototype cell to change from the defaulted text "label" in my tableviewcontroller. 尝试了多种变体并观看了不同的教程,但是无法从tableviewcontroller中的默认文本“标签”更改自定义原型单元格。 I have defined these labels as IBOutlets in the custom prototype file which is appropriately linked. 我已在适当链接的自定义原型文件中将这些标签定义为IBOutlets。 I'm sure I missing something elementary here. 我确定我在这里缺少基本知识。 Any thoughts? 有什么想法吗?

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

        // Date for cell subtitle
        return cell
    }
}

Here is my cell: 这是我的手机:

import UIkit
class UserRecordsTableViewCell: PFTableViewCell {

    @IBOutlet weak var dateEventLabel: UILabel!

    @IBOutlet weak var catEventLabel: UILabel!

    @IBOutlet weak var durationEventLabel: UILabel!

}

And under class in IB I have selected UserRecordsTableViewCell. 在IB的课程下,我选择了UserRecordsTableViewCell。

I have decided the best approach to my desired look is to go with PFTableViewCell provided by parse framework and simply only show two items. 我已决定实现所需外观的最佳方法是使用解析框架提供的PFTableViewCell,并且仅显示两个项目。 Main category and date as subtitle. 主要类别和日期为字幕。 This is opposed to creating a custom cell which works well with text and image label but not well with two text keys. 这与创建一个自定义单元格相反,该自定义单元格与文本和图像标签配合使用很好,但与两个文本键配合使用却效果不好。 Followed this tutorial and was great: 遵循了本教程,很棒:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM