自定义原型单元与Parse - Swift

时间:2015-08-10 19:04:35

标签: ios swift uitableview uilabel custom-cell

我正在构建一个应用程序,我想在其中显示解析的几行数据。

我想在设置单元格UI方面拥有自由,因此我遵循了this tutorial

我有一个CustomCell类来链接我的标签和UIImage

import Foundation
import UIKit
import ParseUI

class CustomCell:  PFTableViewCell {

@IBOutlet weak var nomePrato: UILabel!
@IBOutlet weak var precoPrato: UILabel!


@IBOutlet weak var imagemPrato: PFImageView!


}

另一个设置一切的课程

import UIKit
import Parse
import ParseUI

class TableViewControllerPratos2: 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 = "ProdutosVenda"
    self.textKey = "Nome" 
    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: "ProdutosVenda")
    return query
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell {

    var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! CustomCell!
    if cell == nil {
        cell = CustomCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
    }

    // Extract values from the PFObject to display in the table cell
    if let nome = object?["Nome"] as? String {
        cell?.nomePrato.text = nome
    }
    if let preco = object?["Preco"] as? String {
        cell?.precoPrato.text = preco
    }

    // Display flag image
    var initialThumbnail = UIImage(named: "question")
    cell.imagemPrato.image = initialThumbnail
    if let thumbnail = object?["imagem1"] as? PFFile {
        cell.imagemPrato.file = thumbnail
        cell.imagemPrato.loadInBackground()
    }

    return cell
}
    }

结果:没有错误,只是没有元素和旋转加载动画的单元格的空白轮廓。

0 个答案:

没有答案