I have this data that I need to put inside my UITableView but I’m getting confused on how to properly implement it. I cannot properly separate the values to segregate the Boys data to the Girls data.
{
"QUERY": {
"COLUMNS": [
"NAME",
"GENDER"
],
"DATA": [
[
"Anne",
"Girl"
],
[
"Alex",
"Boy"
],
[
"Vince",
"Boy"
],
[
"Jack",
"Boy"
],
[
"Shiela",
"Girl"
],
[
"Stacy",
"Girl"
]
]
},
"TOTALROWCOUNT": 6
}
I have this codes:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [genderArray count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [genderArray objectAtIndex:section];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [namesArray count];
}
namesArray has all the values returned by NAME while genderArray has all the values of GENDER. I’m getting confused.
AS you are getting confused, break your data into pieces. You want two arrays, one per section. So you want one array of boys names, and another array of girls names.
You can obtain this by iterating through the embedded DATA array.
Turn your data into an NSDictionary object. Your data looks like JSON so…
Extract the data…
Iterate…
Now you have two arrays, one for each of your table sections. Make an array of sections, and put these arrays into it:
Make a separate array for your section headers:
Now your data source methods look like this:
and finally