I have an NSDictionary received from a json request that looks like this:
RESULT : (
{
Id1 = 138;
lat = "45.5292910";
long = "-73.6241500";
order = "2343YY3"
},
{
Id1 = 137;
lat = "45.5292910";
long = "-73.6241500";
order = "2343YY3"
}, etc.
I want to display it in a TableView (CellforRowAtIndexPath), so I obtain the data as NSArray. The method seems inefficient as each key Id1, lat, long, etc is created as an NSArray so that I can display them each with: [self.data1 objectAtIndex:indexPath.row]; [self.data2 objectAtIndex:indexPath.row], etc.
How can I achieve the same thing without creating and using 4 NSArrays? Can I use a single NSArray or the NSMutableDictionary which stores the data?
UPDATED:
When the TableView loads, it is initially empty but I have a button on that same VC that loads a modal view of a form. When I load the form and then dismiss it returning to the TableView, the data is LOADED! Could you suggest what I am missing?
Yes you can use a single array. The trick is to create an array with each array entry holding a dictionary. Then you query the array to populate your tableview.
E.g.: If your array is a property called
tableDataand you have custom tableview cell calledCustomCellthen your code might look something like the following:Similarly, if you have multiple sections in your tableview then you will construct an array of arrays, with each sub-array containing the dictionaries for that section. The code to populate the tableview would look something similar to the following:
TL;DR; Take your dictionaries created from your JSON data and put them in an array. Then query the array to populate the tableview.