简体   繁体   中英

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.

Other columns of same String type are returning properly including the status column shown below.

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. 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:

在此输入图像描述

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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