ios - 地理编码 : Transform NSArray to NSString

标签 ios iphone geocoding

我有一个变量在 .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/

相关文章:

美国大都市区名称数据库?

ios - React Native : RNGeocoder. reverseGeocodeLocation - 可能未处理的 promise 拒绝

iphone - 错误 :on declaring @synthesize method

ios - 我如何解密签名并添加到 objective-c 中的 YouTube 提取的 URL?

ios - 重命名 NSLibraryDirectory 中的所有文件和目录

iphone - 在重新启动时保留应用程序状态

javascript - React Native/Firebase Messaging - 永远不会发送消息/通知

ios - 通过蓝牙将 GPS 位置发送到 iOS 设备

iphone - UIView subview 不显示在 UIScrollView 中

php - 将 PHP/MySQL 与 Google map 结合使用