2011-09-16 5 views
1

Je dois imprimer NSMutableArray *lstAirports;tableau de tri par ordre alphabétique et l'affichage des valeurs de tableau dans la vue tableau

mon tableau d'objet, il imprime tous les enregistrements en vue tableau cellule

Je veux trier ma valeur cellulaire dans l'ordre alphabétique .

comment faire qui svp l'aide de ce code ne m'a pas livré affichage par ordre alphabétique

ceci est mon code de classe contrôleur

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    return app.lstAirports.count; 
} 


// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    airport *a=(airport*)[app.lstAirports objectAtIndex:indexPath.row]; 
    NSLog(@"str:%@",a); 
    cell.textLabel.text =a.Name; 
    cell.detailTextLabel.text=a.Code; 
    // Configure the cell... 

    return cell; 
} 
+0

Code postal de 'airport' classe – Nekto

Répondre

1

Vous pouvez facilement trier une NSMutableArray:

NSSortDescriptor *nameSort = [NSSortDescriptor sortDescriptorWithKey:@"Name" ascending:YES]; 
[lstAirports sortUsingDescriptors:[NSArray arrayWithObject:nameSort]]; 
0

Vous devez commander le tableau à partir de laquelle vous remplissez la table vue, dans ce cas app.lstAirports. This vous apprendra comment le faire.

1

DANS viewWillAppear

NSSortDescriptor *aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Name" ascending:YES]; 
[app.lstAirports sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]]; 
[aSortDescriptor release]; 
0

Trier votre tableau en utilisant NSSortDescriptor

NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"key_name" ascending:YES]; 
[yourArray sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; 
Questions connexes