2015-09-26 58 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 –