【问题标题】:Swift Parse Query TablesSwift Parse 查询表
【发布时间】:2015-09-16 20:45:23
【问题描述】:

我想通过 PFQueryTableView 和 Cell 从我的解析中导入一些数据。我在情节提要上配置了一个表格视图,并为表格视图和它的单元格分配了 PFQueryTableViewController 和 PFQueryTableViewCell。因此,在我的 tableview 控制器上,我正在使用下面的代码,但它在 super.init(className: myClassName) 行上出现错误,并显示“必须调用超类 'PFQueryTableViewController' 的指定初始化程序”的消息

import UIKit
import Parse
import ParseUI

class parseTableView: PFQueryTableViewController {

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

        init(className myClassName: String!) {
        super.init(className: myClassName)

        self.parseClassName = myColoumnName
        self.textKey = "myObjectKey"
        self.pullToRefreshEnabled = true
        self.paginationEnabled = false
    }
}

【问题讨论】:

    标签: ios swift parse-platform


    【解决方案1】:

    你需要覆盖queryForTable:

      // Define the query that will provide the data for the table view
      override func queryForTable() -> PFQuery {
        var query = PFQuery(className: "myClassName")
        return query
      }
    

    此外,在self.parseClassName = myColoumnName 上,您应该提供类名而不是列名。

    另外,您需要覆盖init

      // Initialise the PFQueryTable tableview
      override init(style: UITableViewStyle, className: String!) {
        super.init(style: style, className: className)
      }
    

    您可以找到更多详细信息here

    【讨论】:

      【解决方案2】:

      你必须更换

      super.init(className: myClassName)
      

      super.init(style: .Plain, className: myClassName)
      

      我检查了 PFQueryTableViewController 类的实现,我认为这是因为将 Swift 桥接到 Objective-C 时存在某种缺陷。它与 Swift 中的指定初始化器有关。因为上面的 init 方法没有设置为 Designated Initializer 而下面的是。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-07
        • 1970-01-01
        相关资源
        最近更新 更多