我有一个带有披露按钮的图钉,试图在点击按钮时添加详细视图。
我使用 Apple 的 MapCallouts 作为参考。我收到错误
应用程序试图在目标上推送一个 nil 视图控制器
使用他们的代码示例 -
[self.navigationController pushViewController:self.detailViewController animated:YES];
我在错误的地方实施它吗?我不知道为什么我得到错误。
无法链接所有内容,例如#import、@class @interface @property @implementation @synthesize ... 不知道做什么。
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
// add a detail disclosure button to the callout which will open a new view controller page
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView = rightButton;
}
else {
[mapView.userLocation setTitle:@"Current Location"];
}
return pinView;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
id<MKAnnotation> myAnnotation = [self.mapView.annotations objectAtIndex:0];
[self.mapView selectAnnotation:myAnnotation animated:YES];
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// code to show details view
MapDetailViewController *detailViewController = [[MapDetailViewController alloc] init];
// Adds the above view controller to the stack and pushes it into view
[self.navigationController pushViewController:detailViewController animated:YES];
// We can release it again, because it's retained (and autoreleases in the stack). You can also choose to autorelease it when you allocate it in the first line of code, but make sure you don't call release on it then!
[MapDetailViewController release];
}