1

I managed to create an Array of MyLocation objects with their distance property set in the first of 2 tabs in a tabBarController. In my 2nd tab I get it like so in viewDidLoad:

[self setAnnotationsToSort:myDelegate.annotationsToSort];

and right after this line I call this method:

-(void)sort{
    NSSortDescriptor *sortDescriptor;
    sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"distance" ascending:YES] autorelease];
    NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
    NSArray *sortedArray;
    sortedArray = [self.annotationsToSort sortedArrayUsingDescriptors:sortDescriptors];
    [self.tableView reloadData];
}

which should sort my Array. However my tableView currently loads with the unsorted version of the Array, self.annotationsToSort. How do I reload the tableView but force it to use the new sortedArray?

3 Answers 3

5

You are not doing anything with sortedArray. Try

self.annotationsToSort = [self.annotationsToSort sortedArrayUsingDescriptors:sortDescriptors];
Sign up to request clarification or add additional context in comments.

2 Comments

yeah i tried that but appartently the method sortedArrayUsingDescriptors returns an NSArray and my self.annotationsToSort is NSMutableArray
Just make it a mutableCopy so you can store it as a NSMutableArray
2

Call:

self.annotationsToSort = sortedArray;

Before you call [self.tableView reloadData];

Comments

0

I was missing this step:

self.annotationsToSort = [(NSArray*)sortedArray mutableCopy];

thanks guys

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.