我有一个变量在 .h
文件中声明为 NSArray
并在 .m
中合成
@property (nonatomic, strong) NSArray *placemarksArray; //.h file
@synthesize placemarksArray; //.m
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
if (!geocoder)
geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:searchString completionHandler:^(NSArray* placemarks, NSError* error){
if ([placemarks count] > 0) {
for (CLPlacemark* aPlacemark in placemarks)
{
self.street = placemark.thoroughfare;
self.city = placemark.locality;
self.state = placemark.administrativeArea;
self.zip = placemark.postalCode;
NSMutableString *result = [NSMutableString string];
if (self.street)
[result appendString:self.street];
if (self.street && (self.city || self.state || self.zip))
[result appendString:@", "];
if (self.city)
[result appendString:self.city];
if (self.city && self.state)
[result appendString:@", "];
if (self.state)
[result appendString:self.state];
if (self.zip)
[result appendFormat:@" %@", self.zip];
[self.placemarksArray addObject:result];
NSLog(@"%@", result);
[self.searchDisplayController.searchResultsTableView reloadData];
}
}
}];
return NO;
问题:如何设置 tableView:cellForRowAtIndexPath
以在 tableView
中显示 placemarksArray
?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
以上代码取自 Apple: About Geocoder Objects
最佳答案
添加到您的cellForRowAtIndexPath
方法:
cell.textLabel.text = [placemarksArray objectAtIndex:indexPath.row];
这样做是将每个单元格的文本设置为 placemarksArray 的第 n 个索引处的文本。
例如,第 3 行的单元格将包含索引 3 中的文本数组的。
关于ios - 地理编码 : Transform NSArray to NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15963087/