After so long, I'm still trying to create my first iOS app, and I'm facing another problem yet again =(
Basically, I have pulled JSON data from the web, and I get nested arrays. I have no problems iterating all objects in the array (including the parent array) and placing them in a UITableView. The problem is, I am trying to do something dynamic for the table. I am able to create the correct number of sections for the table. To make it easy for you to visualise what I want to do, here is the JSON data:
{"filter_group":[{"filter_group_id":"1","name":"Location","filter":[{"filter_id":"2","name":"Central"},{"filter_id":"8","name":"East"},{"filter_id":"1","name":"North"},{"filter_id":"10","name":"Northeast"},{"filter_id":"9","name":"West"}]},{"filter_group_id":"3","name":"Price","filter":[{"filter_id":"7","name":"Free"},{"filter_id":"5","name":"$0 - $50"},{"filter_id":"6","name":"$50 - $100"},{"filter_id":"11","name":"$100 - $150"},{"filter_id":"12","name":"$150 - $200"},{"filter_id":"13","name":"Above $200"}]}]}
When you copy the messy chunk that I give you into any JSON viewer, you will see that for now, I have 2 parent arrays with some children each. So basically, "Location" and "Price" will go into different sections. I have successfully done that, but I don't know how to put the names of their children in the correct section of the UITableView.
So my idea now is that I am iterating the array, and putting the children names into another array (this results in names of both sections going into 1 array). I was thinking of creating a new array in each iteration:
for(int i = 0; i < [myArray count]; i++) {
//throw children of different parents into different array
NSMutableArray* newArray[i] = (blah blah blah)
}
You will probably have seen the problem now: newArray[i]. Basically, I can live with the fact that I am creating newArray0, newArray1 etc (I need my app to be dynamic). How do I do this in iOS programming?
OR
After reading what I want to do above, and you have a different idea on how I am to put the data in the respective sections, please enlighten me.
Thank you very much!!! I greatly appreciate any help offered =D
P.S. My replies may be slow, so please forgive me
NSArray* newArray[i] = ...? That code creates a variable-length raw C array of pointers (which point toNSArrayinstances). And you can't even initialize it because it's forbidden. Are you trying to create an array of arrays? If so, you can useNSMutableArrayand fill it in... but this sounds kind of trivial. You need to learn the language before trying to do clever things (and this means that you absolutely need to be proficient in C for writing iOS apps).