iosruby-on-railsios4rubymotion

How to map UITableView cell to a remote database backend?


I'm making a simple To-Do list app for the iPhone with a rails backend.

So far, I can pull all the tasks in a To-Do list from the web app, parse the JSON, and insert it into the UITableView.

The JSON response from rails:

[
  {"id":1,"name":"Buy bread"},
  {"id":8,"name":"Get gas"},
  {"id":14,"name":"Call John"}
]

In the UITableView, a row for each task, the textLabel of the cell is the name of the task:

enter image description here

The problem I'm having now is how to associate the cell with the record id of the task.

Two tasks can have the same name, so I can't just get the id from the hash based only on the name.

I need the record id, so I can post back to the rails app, after the user edits the UItableView (deletes a task for example).

Is there a property I can set on the cell? I feel like I'm missing something obvious. This is my first iPhone app, so please be gentle, hehe.


Solution

  • How are you getting the JSON array to an Objective-C array for use in the table? You'll have to do that again for the ID of the task, and in your - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath method use something like theID = [idArray objectAtIndex:indexPath.row];