iPhone tableview: titleForHeaderInSection derived from array
Posted
by Nic Hubbard
on Stack Overflow
See other posts from Stack Overflow
or by Nic Hubbard
Published on 2010-05-03T23:07:45Z
Indexed on
2010/05/03
23:38 UTC
Read the original article
Hit count: 229
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.
© Stack Overflow or respective owner