簡體   English   中英

Swift-加載本地數據存儲時解析PFQueryTableViewController錯誤

[英]Swift - Parse PFQueryTableViewController Error on loading the LocalDataStore

美好的一天! 我在swift項目中使用了Parse,現在我的問題是將查詢或對象加載並保存到localDataStore,我嘗試了這種方法

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

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


        // Extract values from the PFObject to display in the table cell
        if let placeName = object?["placeName"] as? String {
            cell.cellName.text = placeName
        }
        if let station = object?["station"] as? String {
            cell.cellDetail.text = station
        }
        if let placeImg = object?["placeImg"] as? String {


            let decodedData = NSData(base64EncodedString: placeImg, options: NSDataBase64DecodingOptions(rawValue: 0))
           // var decodedimage = UIImage(data: decodedData!)
            var finImage = UIImage(data: decodedData!)
            cell.cellBgImg.image = finImage



        }

        PFObject.pinAllInBackground(self.objects, block: { (succeeded, error) -> Void in

            if (error == nil) {
            }else {
                println(error!.userInfo)
            }
        })



        return cell
    }

現在在我的queryForTable方法中我有這個

override func queryForTable() -> PFQuery {

        // Start the query object
        var query = PFQuery(className: "Places")

        // Add a where clause if there is a search criteria
        if searchBar.text != "" {
            query.whereKey("filterKeyword", containsString: searchBar.text.lowercaseString)
        }

        // Order the results
        query.orderByAscending("placeName")

        var cReturn = PFQuery()

        if (IJReachability.isConnectedToNetwork()) {

            cReturn = query

        } else {

            cReturn = query.fromLocalDatastore()

        }

        return cReturn
    }

如您所見,我正在使用“ Reachability來檢查設備是否已連接到互聯網。 如果沒有,查詢將返回query.fromLocalDataStore ;如果設備已連接,它將返回普通query以獲取最新數據。

現在,我的問題是,當我關閉互聯網進行測試時,它給我一個錯誤'Method requires Pinning enabled.' 我已經在tableView方法中做了

PFObject.pinAllInBackground(self.objects, block: { (succeeded, error) -> Void in

            if (error == nil) {
            }else {
                println(error!.userInfo)
            }
        })

您認為我做錯了什么? 謝謝!

我認為您應該將方法放在將對象固定在objectsDidLoad()方法內部而不是cellForRowAtindexPath()方法中的位置。

暫無
暫無

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

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