J'ai un objet station définie comme:Les en-têtes de section Objective-C n'apparaissent pas correctement?
@interface RFStation : NSObject {
NSString *stationID;
NSString *callsign;
NSString *logo;
@end
J'ai aussi un NSMutableArray appelé 'StationList' qui est une liste d'objets station. Cette liste est triée par ordre alphabétique par 'indicatif'.
J'ai aussi un autre NSArray appelé 'generalList', contenant des lettres "A" à "Z"
Je veux créer un UITableView avec têtes de section A-Z correspondant à la première lettre de chaque callsign.
J'ai actuellement ces méthodes & objets définis:
- (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];
}
et bien sûr:
- (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;
}
Et pourtant mes têtes ne semblent pas trier les données NSMutableArray correctement. Quel est le problème avec mon code (je soupçonne que c'est le prédicat)