2015-09-26 24 views
0

我使用这种方法来获得建议自动完成,我需要让他们在实现代码如下:访问结果Places API的IOS为

- (void)placeAutocomplete:(NSString *)autoCompleteString { 
    [self.autoCompleteSuggestionsList removeAllObjects]; 
    GMSAutocompleteFilter *filter = [[GMSAutocompleteFilter alloc] init]; 
    filter.type = kGMSPlacesAutocompleteTypeFilterCity; 

    [_placesClient autocompleteQuery:(NSString *)autoCompleteString 
           bounds:nil 
           filter:filter 
          callback:^(NSArray *results, NSError *error) { 
           if (error != nil) { 
            NSLog(@"Autocomplete error %@", [error localizedDescription]); 
            return; 
           } 

           for (GMSAutocompletePrediction* result in results) { 
            //NSLog(@"Result '%@' with placeID %@", result.attributedFullText.string, result.placeID); 
            //NSRange autoCompleteRange = [result.attributedFullText.string rangeOfString:autoCompleteString]; 
            //if (autoCompleteRange.location == 0) { 
            //NSString *stringNow = [NSString stringWithFormat:@"%@",result.attributedFullText.string]; 
            [self.autoCompleteSuggestionsList addObject:result.attributedFullText.string]; 
             //NSLog(@"test : %@",stringNow); 
            //NSLog(@"%@",self.autoCompleteSuggestionsList); 
            //} 
           } 
          }]; 
    [self.autocompleteTableView reloadData]; 
    NSLog(@"%@",self.autoCompleteSuggestionsList); 
} 

,但我不能autocompleteQuery方法的外部访问结果

当记录它显示正确的内部方法,但不是外面, 我使用可变数组来访问它,但我显示正确内,但不是外部。

我不需要使用任何第三方自动填充窗格的建议。 我得到的结果,我只是需要他们从该方法访问,以便它可以访问以显示桌面以及

+0

重装表 –

+0

谢谢哥们非常感谢你(完for循环后): –

+0

谢谢谢谢,请通过为他人 –

回答

1

你必须重新加载块内的数据。

这样做的原因很简单,因为块在不同的线程中运行,所以当它完成它的执行时,主线程会回调块,这就是为什么我们需要在块中重新加载表。自动完成块内

- (void)placeAutocomplete:(NSString *)autoCompleteString { 
    [self.autoCompleteSuggestionsList removeAllObjects]; 
    GMSAutocompleteFilter *filter = [[GMSAutocompleteFilter alloc] init]; 
    filter.type = kGMSPlacesAutocompleteTypeFilterCity; 

    [_placesClient autocompleteQuery:(NSString *)autoCompleteString 
           bounds:nil 
           filter:filter 
          callback:^(NSArray *results, NSError *error) { 
           if (error != nil) { 
            NSLog(@"Autocomplete error %@", [error localizedDescription]); 
            return; 
           } 

           for (GMSAutocompletePrediction* result in results) { 

            [self.autoCompleteSuggestionsList addObject:result.attributedFullText.string]; 

           } 
           [self.autocompleteTableView reloadData]; 
          }]; 
    NSLog(@"%@",self.autoCompleteSuggestionsList); 
} 
+0

感谢编辑@chirag shah –

+1

快乐编码@Saurabh –