详细视图中的注释标题和副标题

时间:2011-07-05 16:55:30

标签: iphone objective-c cocoa-touch mkmapview

我有一个从地图推送的详细视图。我试图从注释中获取标题和副标题以在详细视图中显示。我可以在导航栏中显示标题,但我不能让它们显示为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;

}

非常感谢任何帮助。谢谢!

1 个答案:

答案 0 :(得分:1)

目前尚未实例化nameaddress。他们的价值将是nil

nameTextaddressText声明为属性,在此方法中设置它们,然后更新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