【发布时间】:2015-09-26 10:52:00
【问题描述】:
我正在使用这种方法来获取建议,我需要在 tableview 中显示它们:
- (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 方法之外的结果
登录时,它在方法内部正确显示,但在外部不正确, 我正在使用可变数组来访问它,但我在内部正确显示但在外部显示不正确。
我不需要关于使用任何第三方自动完成 pod 的建议。 我得到了结果,我只需要从方法中访问它们,以便也可以访问它以显示 tableview
【问题讨论】:
-
在 autoComplete 块内重新加载表。(完成 for 循环后)
-
谢谢哥们,非常感谢:
-
谢谢谢谢,请把这个贴出来作为其他人的答案
标签: ios objective-c uitableview google-places-api