1

I have to print NSMutableArray *lstAirports;

my array of object it print all record in table view cell

I want to sort my cell value in alphabetical order.

how to do that please some help this code not given me display in alphabetical order

this is my code of controller class

- (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

4 Answers 4

1

You can easily sort a NSMutableArray:

NSSortDescriptor *nameSort = [NSSortDescriptor sortDescriptorWithKey:@"Name" ascending:YES];
[lstAirports sortUsingDescriptors:[NSArray arrayWithObject:nameSort]];
Sign up to request clarification or add additional context in comments.

Comments

1

IN viewWillAppear

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

Comments

0

You need to order the array from which you populate the table view, in this case app.lstAirports. This will teach you how to do it.

Comments

0

Sort your array using NSSortDescriptor

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.