Dou*_*ira 5 iphone cocoa-touch objective-c uitableview mapkit
我这样得到了2分的距离
[userLocation distanceFromLocation: annotationLocation] / 1000;
Run Code Online (Sandbox Code Playgroud)
并将其设置为tableview的副标题,如图像bellow screenshot http://i41.tinypic.com/ruxv74.png
问题是,我可以按距离(副标题)订购此表吗?
谢谢!
并抱歉坏英语= x
您可以按照任何方式订购UITableView的单元格,但在创建表格的数据源之前必须先显示它们.如果使用NSFetchResultsController,则可以将距离作为排序描述符.如果您使用的是简单的NS(Mutable)数组,请在将其作为表的源之前对其进行排序.
像克里斯说的那样,你可以做到
NSSortDescriptor *titleSorter= [[NSSortDescriptor alloc] initWithKey:@"annotationLocation" ascending:YES];
Run Code Online (Sandbox Code Playgroud)
如果你正在使用的是NSArray,那么:
[arrayOfObjects sortUsingDescriptors:[NSArray arrayWithObject:titleSorter];
Run Code Online (Sandbox Code Playgroud)
如果是NSFetchResultsController:
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:titleSorter, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1257 次 |
| 最近记录: |