我设法创建了一个Array
的MyLocation
对象,其中的距离属性设置在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
?
是的,我尝试过,但appartently方法sortedArrayUsingDescriptors返回一个NSArray和我self.annotationsToSort是NSMutableArray – marciokoko 2013-02-15 23:38:41
只是让它成为一个'mutableCopy',所以你可以将其存储为'NSMutableArray' – 2013-02-16 00:01:10