我正在制作一个使用 iOS MapKit 在地图上显示注释的应用程序。当用户点击注释时,标注窗口会弹出并显示平铺、副标题和详细信息披露按钮。当用户点击详细信息披露按钮时,我需要弹出更多信息。
此附加信息可能是弹出窗口或其他加载的视图。我试图弄清楚如何最好地做到这一点。
现在,我在 annotationView 实现文件中使用以下代码添加了 Detail Disclosure Button。请注意这一行self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]
......并且还要注意它正在为三个 annotationTypes 完成:
这是添加的位置:
- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
iCodeBlogAnnotation *myAnnotation = (iCodeBlogAnnotation*)annotation;
// setup the if/else statements
if ([myAnnotation annotationType] == iCodeBlogAnnotationTypeHotels)
{
self = [super initWithAnnotation:myAnnotation reuseIdentifier:reuseIdentifier];
self.frame = CGRectMake(0, 0, kWidth, kHeight);
self.backgroundColor = [UIColor clearColor];
self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Hotel.png"]];
imageView.frame = CGRectMake(kBorder, kBorder, kWidth - 2 * kBorder, kWidth - 2 * kBorder);
[self addSubview:imageView];
}
else if([myAnnotation annotationType] == iCodeBlogAnnotationTypeAerialShots)
{
self = [super initWithAnnotation:myAnnotation reuseIdentifier:reuseIdentifier];
self.frame = CGRectMake(0, 0, kWidth, kHeight);
self.backgroundColor = [UIColor clearColor];
self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"StreetView.jpg"]];
imageView.frame = CGRectMake(kBorder, kBorder, kWidth - 2 * kBorder, kWidth - 2 * kBorder);
[self addSubview:imageView];
}
else if ([myAnnotation annotationType] == iCodeBlogAnnotationTypeStreets)
{
self = [super initWithAnnotation:myAnnotation reuseIdentifier:reuseIdentifier];
self.frame = CGRectMake(0, 0, kWidth, kHeight);
self.backgroundColor = [UIColor clearColor];
self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Street.png"]];
imageView.frame = CGRectMake(kBorder, kBorder, kWidth - 2 * kBorder, kWidth - 2 * kBorder);
[self addSubview:imageView];
}
然后,在我的 viewController 实现文件中,我有以下方法来检测用户何时点击了详细信息披露按钮:
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
// add code here for what you want to do
}
我应该在上述方法中添加什么代码才能加载一些新的弹出窗口或包含详细信息的新视图?
我尝试创建一个新的 detailViewController 类,并将以下代码添加到上述 controllTapped 方法中的“在此处添加代码”中:
iCodeBlogMapDetailViewController *dvc = [[iCodeBlogMapDetailViewController alloc] init];
[self.navigationController pushViewController:dvc animated:YES];
但什么也没发生。
我的下一步是什么?
谢谢,