0

我想在closestStation函数开始之前隐藏multipleSearchView但没有成功,它隐藏但在closestStation完成之后

- (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
}
4

3 回答 3

1

那是因为你在主队列中有一个繁重的操作。把你-closestStation:的后台队列来解决这个问题。

于 2013-09-10T16:31:08.073 回答
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];
}

}
于 2013-09-10T16:35:52.380 回答
0

尝试使用performSelectorInBackground.

于 2013-09-10T16:38:05.340 回答