iPhone tableview: titleForHeaderInSection derived from array
- by Nic Hubbard
I have a tableview that is populated by an array. Currently the tableview has no grouping. What I would like to do is check a value of each array object, such as State, and group all the CA items together, all the OR items together, etc. Then, assign those groups a title.
The array is dynamic, and will grow and get new values in the future, so I can't hardcode titles, I would like these to somehow come from my initial array.
Currently I am using the following, but it does not take into account sorting of the array, or if I removed all of the items in the array that have to do with California.
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (section == 0) {
return @"California";
} else if (section == 1) {
return @"Washington";
} else {
return @"Utah";
}
}//end tableView
So, I am confusing myself as to how this would be possible. Any tips would be appreciated.