2013-02-15 85 views
1

我设法创建了一个ArrayMyLocation对象,其中的距离属性设置在tabBarController的2个选项卡中的第一个中。在我的第二个选项卡中,我得到它像这样在viewDidLoad:此行之后如何为阵列工作制作NSSortDescriptor?

[self setAnnotationsToSort:myDelegate.annotationsToSort]; 

,右我调用这个方法:

-(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]; 
} 

应该排序我Array。但是,我的tableView当前加载了Array,self.annotationsToSort的未排序版本。如何重新加载tableView但强制它使用新的sortedArray

回答

5

你没有做任何事情sortedArray。尝试

self.annotationsToSort = [self.annotationsToSort sortedArrayUsingDescriptors:sortDescriptors]; 
+0

是的,我尝试过,但appartently方法sortedArrayUsingDescriptors返回一个NSArray和我self.annotationsToSort是NSMutableArray – marciokoko 2013-02-15 23:38:41

+0

只是让它成为一个'mutableCopy',所以你可以将其存储为'NSMutableArray' – 2013-02-16 00:01:10

2

电话:

self.annotationsToSort = sortedArray;

在打电话前[self.tableView reloadData];

0

我错过了这一步:

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

谢谢你们