我是 iOS 编程新手,在视图控制器之间传递数据时遇到了麻烦。
我有一个视图控制器,它对地图视图上的注释进行地理编码,并将地址设置为注释视图的标题。注释视图有一个标注按钮,可将另一个视图推送到堆栈,该堆栈有一个标签,我希望地理编码的地址显示为标签。这是一些代码:
这是我放下别针的地方:
-(void)press:(UILongPressGestureRecognizer *)recognizer
{
CGPoint touchPoint = [recognizer locationInView:worldView];
CLLocationCoordinate2D touchMapCoordinate = [worldView convertPoint:touchPoint toCoordinateFromView:worldView];
geocoder = [[CLGeocoder alloc]init];
CLLocation *location = [[CLLocation alloc]initWithCoordinate:touchMapCoordinate
altitude:CLLocationDistanceMax
horizontalAccuracy:kCLLocationAccuracyBest
verticalAccuracy:kCLLocationAccuracyBest
timestamp:[NSDate date]];
[geocoder reverseGeocodeLocation:location
completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"reverseGeocoder:completionHandler: called");
if (error) {
NSLog(@"Geocoder failed with error: %@", error);
}
if (placemarks && placemarks.count > 0)
{
CLPlacemark *place = [placemarks objectAtIndex:0];
_address = [NSString stringWithFormat:@"%@ %@, %@ %@", [place subThoroughfare], [place thoroughfare], [place locality], [place administrativeArea]];
if (UIGestureRecognizerStateBegan == [recognizer state]) {
_addressPin = [[MapPoint alloc]initWithCoordinate:touchMapCoordinate
title:_address];
[worldView addAnnotation:_addressPin];
}
}
}];
}
这是我希望显示地址的视图的代码:
#import <UIKit/UIKit.h>
@class MapPoint;
@interface PinViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate,UITextFieldDelegate>
{
__weak IBOutlet UILabel *addressLabel;
}
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (strong, nonatomic) MapPoint *pin;
-(void)takePicture:(id)sender;
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
@end
#import "PinViewController.h"
#import "MapPoint.h"
@interface PinViewController ()
@end
@implementation PinViewController
@synthesize imageView, pin;
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[addressLabel setText:[pin title]];
}
MapPoint 类具有 title 属性和 subtitle 属性。当 PinViewController 被推到堆栈顶部时,我尝试将标签的文本设置为引脚的标题,但标签不显示任何文本。有人可以帮助我并告诉我我错过了什么吗?非常感谢您的帮助。