我有一个从地图推送的详细视图。我试图从注释中获取标题和副标题以在详细视图中显示。我可以在导航栏中显示标题,但我不能让它们显示为UILabels。我的界面构建器中的UILabel对于MapDetailInfo都连接到“name”和“address”,但是当按下视图时它们不会填充。这是我的代码:
在我的地图视图控制器中
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
MapDetailInfo *abc = [[MapDetailInfo alloc]init];
abc.title = view.annotation.title;
[self.navigationController pushViewController:abc animated:YES];
nameText.text = view.annotation.title;
addressText.text = view.annotation.subtitle;
}
在我的详细信息视图控制器中:
- (void)viewDidLoad
{
[super viewDidLoad];
BusinessListingsPart3ViewController *blv = [[BusinessListingsPart3ViewController alloc] init];
name.text = blv.nameText.text;
address.text = blv.addressText.text;
}
非常感谢任何帮助。谢谢!
答案 0 :(得分:1)
目前尚未实例化name
和address
。他们的价值将是nil
。
将nameText
和addressText
声明为属性,在此方法中设置它们,然后更新viewDidLoad
方法中的标签。
<小时/> 的 MapDetailInfo.h 强>
@interface MapDetailInfo: .... {
NSString * nameText;
NSString * addressText;
....
}
@property (nonatomic, copy) NSString * nameText;
@property (nonatomic, copy) NSString * addressText;
....
<强> MapDetailInfo.m 强>
@implementation MapDetailInfo
@synthesize nameText;
@synthesize addressText;
....
在当前方法mapView:annotationView:calloutAccessoryTapped:
中,替换
abc.name.text= view.annotation.title;
abc.address.text = view.annotation.subtitle;
与
abc.nameText = view.annotation.title;
abc.addressText = view.annotation.subtitle;
在MapDetailInfo
的{{1}}方法中,添加
viewDidLoad