簡體   English   中英

在SWIFT中使用PFQueryTableViewController和PARSE的自定義表單元格

[英]Custom Table Cells with PFQueryTableViewController with PARSE in SWIFT

所有,

我已經使單元格與普通單元格一起正常工作,但是我試圖用筆尖等創建自定義單元格,然后使用PFQueryTableViewController將其鏈接到PARSE。

這是我的代碼:

class CustomCell: PFTableViewCell
{
    @IBOutlet var EventTypeImage: UIImageView!
    @IBOutlet var titleLabel: UILabel!

    }




class TableViewController: PFQueryTableViewController {



    override init!(style: UITableViewStyle, className: String!) {
        super.init(style: style, className: className)
    }


    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        self.parseClassName = "Events_"
        self.pullToRefreshEnabled = true
        self.paginationEnabled = true
        //self.objectsPerPage = 5
        //self.textKey = "TypeOfVenue_"
     }

    override func viewDidLoad() {

        var nib = UINib(nibName: "CustomTableViewCell", bundle: nil)
        tableView.registerNib(nib, forCellReuseIdentifier: "CustomCell")
    }



    override func queryForTable() -> PFQuery! {

        var query = PFQuery(className: self.parseClassName)

        if (objects.count == 0)
        {
            query.cachePolicy = kPFCachePolicyNetworkOnly
        }

        return query


    }



     override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell!
     {
        var custom = CustomCell()

        var cell = tableView.dequeueReusableCellWithIdentifier("CustomCell") as PFTableViewCell!

        custom.titleLabel?.text = object["Title"] as NSString
        return cell


     }

因此,我創建了一個自定義單元,並將其與頂部的CustomCell類鏈接。 在CellForRowatIndexPath中。 我創建了CustomCell類的新實例,並從中獲取了titlelabel,然后將其強制轉換為NSstring並使用PARSE來獲取“對象”。

我沒有任何錯誤。 我在表格視圖中看到的只是一個旋轉的輪子,上面顯示“正在加載”。

任何建議都是很棒的。

遇到類似的問題,即筆尖未裝入。 然后,我意識到我可以在情節提要中的tableviewcontroller的原型中創建自定義單元格,就像我所做的那樣,然后如圖所示在身份檢查器中更改類。 這里QuestionCell將是您的自定義單元文件。

在此處輸入圖片說明

我將CustomCell分為不同的類型,並確保您已在原型身份檢查器中選擇了該選項。 同樣,確保樣式是自定義的,並確保故事板上的任何標簽都與新CustomCell類中的iboutlet連接。

在此處輸入圖片說明

然后,您可以刪除

var nib = UINib(nibName: "CustomTableViewCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "CustomCell")

因為您正在使用原型。

然后更換

var cell = tableView.dequeueReusableCellWithIdentifier("CustomCell") as PFTableViewCell!

var cell:CustomCell = tableView.dequeueReusableCellWithIdentifier("CustomCell", forIndexPath: indexPath) as? CustomCell

而且您應該很好走! 讓我知道這個是否奏效!

向此init方法添加初始化程序屬性時,我還有一個旋轉的加載輪:

required init(coder aDecoder: NSCoder)

但是,這樣做卻有效:

//class TableViewController: PFQueryTableViewController

override init!(style: UITableViewStyle, className: String!) {
    super.init(style: style, className: className)

    self.parseClassName = "todo"
    self.pullToRefreshEnabled = true
    self.paginationEnabled = true
    self.objectsPerPage = 30
    self.tableView.estimatedRowHeight = 80
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM