I have a detail view that is pushed from a map. I am trying to get the title and subtitle from the annotation to show in the detail view. I can get the title to show in the Navigation bar, but I cannot get them to show up as UILabels. I have UILabels in my interface builder for the MapDetailInfo all connected to the "name" and "address", but they will not fill when the view is pushed. Here is my code:
In My Map View Controller
- (void)mapView:(MKMapView *)mapView
an开发者_StackOverflow社区notationView:(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;
}
In My Detail View Controller:
- (void)viewDidLoad
{
[super viewDidLoad];
BusinessListingsPart3ViewController *blv = [[BusinessListingsPart3ViewController alloc] init];
name.text = blv.nameText.text;
address.text = blv.addressText.text;
}
Any help would be much appreciated. Thanks!
Both name
and address
are not instantiated at this time. Their values will be nil
.
Declare nameText
and addressText
as properties, set them in this method and then later update the labels in the viewDidLoad
method.
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;
....
In the current method mapView:annotationView:calloutAccessoryTapped:
, replace
abc.name.text= view.annotation.title;
abc.address.text = view.annotation.subtitle;
with
abc.nameText = view.annotation.title;
abc.addressText = view.annotation.subtitle;
And in MapDetailInfo
's viewDidLoad
method, add
self.name.text = nameText;
self.address.text = addressText;
精彩评论