我有一个基于 UITabBarController 的应用程序:
1) 从 Web 获取数据并将其解析到 CD 中(这工作正常)。[In Tab 1] 2) 然后当第二个选项卡 [In Tab 2] 被选中时,它运行这个方法:
{ viewDidLoad > loadRecordsFromCD (performBlockAndWait) > populateLocationsToSort }
- (void)populateLocationsToSort {
//1. Get UserLocation based on mapview
self.userLocation = [[CLLocation alloc] initWithLatitude:self.userLocation.coordinate.latitude longitude:self.userLocation.coordinate.longitude];
// Loop thru dictionary-->Create locations
// 2. Loop thru dictionary to get Custom Objects
for (Location * locationObject in self.farSiman) {
// 3. Unload objects values into locals
//PARSE ALL DATA
NSString *coordenadas = locationObject.coordenadas;
NSArray *coordinatesArray = [coordenadas componentsSeparatedByString:@","];
NSString * latitude = [coordinatesArray objectAtIndex:0];
NSString * longitude = [coordinatesArray objectAtIndex:1];
NSString * storeDescription = locationObject.nombrePublico;
NSString * address = locationObject.direccion;
NSString * ciudad = locationObject.ciudad;
NSString * horario = locationObject.horario;
NSString * hor_LV = locationObject.hor_LV;
NSString * hor_S = locationObject.hor_S;
NSString * hor_D = locationObject.hor_D;
NSString * telefono = locationObject.telefono;
NSString * celular_TA = locationObject.celular_TA;
NSString * celular_TB = locationObject.celular_TB;
NSString * hrs24 = locationObject.hrs24;
NSString * driveThru = locationObject.driveThru;
//NSString * estado = locationObject.estado;
NSString * estado;
// IF self.open24hrs SELECTED
if (self.open24hrs) {
// Set it based on TimeComparator
if ([TimeComparator dealWithTimeStrings2:locationObject.hor_LV]) {
estado = @"Abierta";
} else {
estado = @"Cerrada";
}
} else {
estado = locationObject.estado;
}
// 4. Create MyLocation object based on locals gotten from Custom Object
CLLocationCoordinate2D coordinate;
coordinate.latitude = latitude.doubleValue;
coordinate.longitude = longitude.doubleValue;
MyLocation *annotation = [[MyLocation alloc] initWithName:storeDescription address:address coordinate:coordinate distance:0 ciudad:ciudad horario:horario telefono:telefono hrs24:hrs24 driveThru:driveThru hor_LV:hor_LV hor_D:hor_D hor_S:hor_S celular_TA:celular_TA celular_TB:celular_TB estado:estado];
// 5. Calculate distance between locations & uL
CLLocation *pinLocation = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude longitude:annotation.coordinate.longitude];
CLLocationDistance calculatedDistance = [pinLocation distanceFromLocation:self.userLocation];
annotation.distance = calculatedDistance/1000;
//Add annotation to local NSMArray
[self.annotationsToSort addObject:annotation];
} //ENDS FOR LOOP
//SORT the created annotationsToSort
[self sort];
}
它采用从 CD 获取中填充的数组并从中创建对象。它创建新对象,因为它必须获取 hor_LV 字段,将其解析为日期并将它们与现在进行比较以确定 location.estado。
目前有 84 条记录被提取,我已经注意到从我点击第二个选项卡(这个 tableviewcontroller)到它实际显示在屏幕上的时间之间存在延迟。
我无法预解析这个数组,因为用户在 Tab 1 上设置了一些过滤器,这些过滤器在从数据库中获取数据之前被传递到 Tab 2。所以我知道提取必须在 Tab 2 加载时发生。我的问题是,我能做些什么来加快速度或不让滞后如此明显?