[英]Unable to get value of Parse.com column
這是我遇到過的最瘋狂的錯誤。 我試圖從Orders表中名為nameRetailer的列中獲取值,但它一直變為零。
具有相同String類型的其他列正確返回,包括下面顯示的status列。
什么可能導致這個? 拼寫肯定是正確的。 請幫忙....
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let date = object?.objectForKey("dueDate") as! NSDate
let strDate = dateFormatter.stringFromDate(date)
cell.retailerName.text = object?.objectForKey("nameRetailer") as? String
cell.orderDueDate.text = strDate
cell.orderStatus.text = object?.objectForKey("status") as? String
當我嘗試打印對象的值?.objectForKey(“nameRetailer”)時,它在控制台中顯示為nil。 在解析數據瀏覽器中,列包含數據並已刷新。
更新:添加其他代碼:
負責表視圖的整個類代碼:
class OrderViewController: PFQueryTableViewController {
override func queryForTable() -> PFQuery {
let query = PFQuery(className: "Orders")
query.cachePolicy = .CacheElseNetwork
query.orderByAscending("createdAt")
return query
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! OrdersTableViewCell
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let date = object?.objectForKey("dueDate") as! NSDate
let strDate = dateFormatter.stringFromDate(date)
cell.retailerName.text = object?.objectForKey("nameRetailer") as? String
cell.orderDueDate.text = strDate
cell.orderStatus.text = object?.objectForKey("status") as? String
print(object)
//let imageFile = object?.objectForKey("image") as PFFile
//cell.cellImageView.image = UIImage(named:"placeholder")
//cell.cellImageView.file = imageFile
//cell.cellImageView.loadInBackground()
return cell
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.row + 1 > self.objects?.count
{
return 44
}
let height = super.tableView(tableView, heightForRowAtIndexPath: indexPath)
return height
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row + 1 > self.objects?.count
{
self.loadNextPage()
tableView.deselectRowAtIndexPath(indexPath, animated: true)
self.performSegueWithIdentifier("showDetail", sender: self)
}
}
訂單表的圖像:
這是打印PFObject的日志快照:
這是顯示兩行的更新快照
您已將緩存策略設置為首先在本地緩存中查找數據,這可能是陳舊的。
更改:
query.cachePolicy = .CacheElseNetwork
至
query.cachePolicy = .NetworkOnly // ignores cache on reading, but saves to cache
要么
query.cachePolicy = .IgnoreCache // no cache at all -- this is the default
(或根據您的具體情況和用例的其他適當值)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.