我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
显示placemarksArray
在tableView
?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
上面的代码取自 Apple: About Geocoder Objects