gpt4 book ai didi

Swift - 加载 LocalDataStore 时解析 PFQueryTableViewController 错误

转载 作者:行者123 更新时间:2023-11-30 14:14:50 25 4
gpt4 key购买 nike

美好的一天!我在我的 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() 方法中。

关于Swift - 加载 LocalDataStore 时解析 PFQueryTableViewController 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31318724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com