简体   繁体   English

无法获得Parse.com专栏的价值

[英]Unable to get value of Parse.com column

This is the craziest error I've encountered ever. 这是我遇到过的最疯狂的错误。 I am trying to get the value from a column called nameRetailer in the Orders table, but it keeps getting nil. 我试图从Orders表中名为nameRetailer的列中获取值,但它一直变为零。

Other columns of same String type are returning properly including the status column shown below. 具有相同String类型的其他列正确返回,包括下面显示的status列。

What could lead to this? 什么可能导致这个? The spelling is certainly correct. 拼写肯定是正确的。 Please help.... 请帮忙....

 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

When I tried to print the value of object?.objectForKey("nameRetailer"), it shows nil in console. 当我尝试打印对象的值?.objectForKey(“nameRetailer”)时,它在控制台中显示为nil。 In the parse data browser, column has data and was refreshed. 在解析数据浏览器中,列包含数据并已刷新。

在此输入图像描述

Update: Adding additional code: 更新:添加其他代码:

The entire class code responsible for the table view: 负责表视图的整个类代码:

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)
        }
    }

An image of the table of orders: 订单表的图像:

在此输入图像描述

and here is the log snapshot of printing PFObject: 这是打印PFObject的日志快照:

在此输入图像描述

And here is the updated snapshots showing the two rows 这是显示两行的更新快照

在此输入图像描述

You have set your cache policy to start by looking up data in the local cache, which may be stale. 您已将缓存策略设置为首先在本地缓存中查找数据,这可能是陈旧的。

Change: 更改:

    query.cachePolicy = .CacheElseNetwork

to

    query.cachePolicy = .NetworkOnly // ignores cache on reading, but saves to cache

or 要么

    query.cachePolicy = .IgnoreCache // no cache at all -- this is the default

(or other appropriate value based on your specific context and use case) (或根据您的具体情况和用例的其他适当值)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM