根据标签地址的结果隐藏文本

时间:2014-05-20 13:47:15

标签: ios label cllocationmanager

在我的应用程序中,当用户按下按钮时,用户将在标签上显示他的地址。根据用户的位置,结果有时等于"(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.

1 个答案:

答案 0 :(得分:0)

试试这个

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:@""];