У меня есть Станция объект, определенный как:
@interface RFStation : NSObject {
NSString *stationID;
NSString *callsign;
NSString *logo;
@end
У меня также есть NSMutableArray с именем ' StationList ', который представляет собой список объектов Station. Этот список отсортирован в алфавитном порядке по ' позывной '.
У меня также есть другой NSArray с именем ' generalList ', содержащий буквы от "A" до "Z"
Я хочу создать UITableView с заголовками разделов A-Z, соответствующими первой букве каждого позывного.
У меня в настоящее время определены эти методы и объекты:
- (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];
}
и, конечно:
- (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;
}
И все же мои заголовки не отображаются для правильной сортировки данных NSMutableArray. Что не так с моим кодом (я подозреваю, что это предикат)