2

I have an object with dictionary properties I'm trying to access and display on a tableview cell. I haven't dealt with dictionary type data before, so displaying it has kind of confused me..

this is the object. Its from the class PoolAccount and the data i want to access is in the column "serviceHistory"

var poolHistory:PFObject = PFObject(className: "PoolAccount")
 Print(poolHistory.valueForKey("serviceHistory")!.count!)
 //returns this data

enter image description here

enter image description here

enter image description here

  //How do i cast this data so i can use it in a tableview cell?
  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell


  cell.textLabel?.text = ??
7
  • can you post a picture of the class you have in parse Commented Aug 17, 2015 at 19:25
  • i updated it with a couple pictures @Lamar, its an array of dictionary values. Commented Aug 17, 2015 at 19:29
  • you have to use the query those objects from the background using findObjectsInBackgroundWithBlock save it into a dictionary then you could populate it into a cell Commented Aug 17, 2015 at 19:36
  • anyway to take the current object not my tableview and cast it into a dictionary? Commented Aug 17, 2015 at 19:52
  • i don't really understand what you just said.? Commented Aug 17, 2015 at 19:54

1 Answer 1

1

I think you should change "serviceHistory" column type to Object. You can use NSDictionary

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
     let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell

var data = poolHistory["serviceHistory"] as! NSArray

var element = data[indexPath.row] as! NSDictionary
var phValue = element["PH"] as! Int

cell.textLabel?.text = "\(phValue)"

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

3 Comments

I need to save multiple objects to this column, does this column as an object only hold one object or can it consist of an array of objects?
sorry i couldn't understand your case. i edited code probably this should work. in your case you use an array ob objects.
unfortunately i can only add one object to the column and not multiple objects unless the column is of type array...having a column of object doesn't allow that..

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.