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

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 に答える