在我的应用程序中,当用户按下按钮时,他的地址将显示在标签上。根据用户的位置,结果有时等于"(null)"。这种情况经常发生在地址的编号上。例如:*Infinite Loop (null), 95014 Cupertino, CA, United States*
。我如何隐藏(null),如果它出现?
NSLog(@"Resolving the Address");
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
_addressLabel.text = [NSString stringWithFormat:@"%@ %@n%@ %@n%@n%@",
placemark.thoroughfare, placemark.subThoroughfare,
placemark.postalCode, placemark.locality,
placemark.administrativeArea,
placemark.country];
} else {
NSLog(@"%@", error.debugDescription);
}`
Thank you in advance.
试试这个
NSString *addressString = [NSString stringWithFormat:@"%@ %@n%@ %@n%@n%@",
placemark.thoroughfare, placemark.subThoroughfare,
placemark.postalCode, placemark.locality,
placemark.administrativeArea,
placemark.country];
_addressLabel.text = [addressString stringByReplacingOccurrencesOfString:@"(null)"
withString:@""];