I have a Station object defined as:
@interface RFStation : NSObject {
NSString *stationID;
NSString *callsign;
NSString *logo;
@end
I also have an NSMutableArray called 'StationList' which is a list of Station objects. This list is sorted alphabetically by 'callsign'.
I also have another NSArray called 'generalList', containing letters "A" through "Z"
I want to create a UITableView with section headers A-Z corresponding to the first letter of each callsign.
I currently have these methods & objects defined:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [generalList count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [generalList objectAtIndex:section];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSPredicate *filter = [NSPredicate predicateWithFormat:@"callsign beginswith[cd] %@",[generalList objectAtIndex:section]];
return [[stationList filteredArrayUsingPredicate:filter] count];
}
and of course:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
RFStation *aStation = [stationList ObjectAtIndex:[indexPath row]];
static NSString *identity = @"MainCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identity];
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0.0, 0.0, 0.0, 0.0) reuseIdentifier:identity] autorelease];
}
cell.text = aStation.callsign;
return cell;
}
And yet my headers do not appear to sort the NSMutableArray data correctly. What is wrong with my code (I suspect it's the predicate)