我想在最近的Station功能开始之前隐藏多个SearchView但是没有成功,它会在最近的站点完成后隐藏
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath
{
if (tableView == self.localityTableView){
[self.multipleSearchView setHidden:TRUE];
[self closestStation:locality.latitude :locality.longitude];
}
}
- (void) closestStation :(float) latitude :(float) longitude{
// this function takes 3 or 4 second
}
答案 0 :(得分:1)
那是因为你在主队列中有一个繁重的操作。将您的-closestStation:
放入后台队列以解决此问题。
答案 1 :(得分:0)
UI更新也需要一段时间(在下一个周期中)。试试这个:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
if (tableView == self.localityTableView){
[self.multipleSearchView setHidden:TRUE];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self closestStation:locality.latitude :locality.longitude];
});
}
}
- (void) closestStation :(float) latitude :(float) longitude{
// SQLite query here to find the closest places
if (self.places.count == 0){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Results"
message:@"No results match your
search. try with other criteria"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
else {
[self displayAnnotations];
}
}
-(void) displayAnnotations{
NSMutableArray *annotations = [[NSMutableArray alloc] init];
for (Station *item in self.places)
{
PlaceAnnotation *annotation = [[PlaceAnnotation alloc] init];
annotation.coordinate = item.coordinate;
annotation.title = item.stationName;
annotation.subtitle = item.address1;
annotation.station = item;
[annotations addObject:annotation];
}
if (annotations.count > 0){
[self.mapView addAnnotations:annotations];
}
}
答案 2 :(得分:0)
尝试使用performSelectorInBackground
。