3

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.

enter image description here

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:

enter image description here

and here is the log snapshot of printing PFObject:

enter image description here

And here is the updated snapshots showing the two rows

enter image description here

15
  • Two rows having retailer name don't necessarily mean that whole column will have retailer name. Show us the object in Data browser, for which retailer name is returned nil. Commented Dec 18, 2015 at 10:12
  • There are only 2 rows and each record has multiple columns and one of them is nameRetailer shown above. How come status column showing and all others showing except this? Commented Dec 18, 2015 at 10:14
  • When you print the PFObject, can you see retailers name in there? Commented Dec 18, 2015 at 10:17
  • @NSNoob no it doesn't show...@_@ Commented Dec 18, 2015 at 10:20
  • 1
    Change query.cachePolicy = .CacheElseNetwork to query.cachePolicy = .NetworkOnly to force reload from server Commented Dec 18, 2015 at 10:40

1 Answer 1

3

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.