1

NSArray.h文件中声明了一个变量并在其中合成.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显示placemarksArraytableView

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  

上面的代码取自 Apple: About Geocoder Objects

4

1 回答 1

2

添加到您的cellForRowAtIndexPath方法中:

cell.textLabel.text = [placemarksArray objectAtIndex:indexPath.row];

这将做的是将每个单元格的文本设置为等于第 n 个索引处的文本placemarksArray.例如,第 3 行的单元格将具有数组索引 3 中的文本。

于 2013-04-12T05:35:29.870 回答