当用户点击地图上的详细信息披露按钮时,如何加载新视图?

时间:2013-04-09 14:58:40

标签: ios annotations mapkit

我正在创建一个使用iOS MapKit在地图上显示注释的应用程序。当用户点击注释时,会弹出标注窗口并显示“平铺”,“字幕”和“详细信息披露”按钮。当用户点击详细信息披露按钮时,我需要弹出其他信息。

此附加信息可以是弹出窗口或其他加载的视图。我想弄清楚如何最好地做到这一点。

现在我在annotationView实现文件中使用以下代码添加了Detail Disclosure按钮。注意行self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure] ...并且还注意到它正在为THREE 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

}

我应该在上面的方法中添加什么代码才能加载一些新的弹出窗口或新视图来保存详细信息?

我尝试创建一个新的detailedViewController类,并将以下代码添加到上面的controllTapped方法中的“add code here”中:

iCodeBlogMapDetailViewController *dvc = [[iCodeBlogMapDetailViewController alloc] init];
[self.navigationController pushViewController:dvc animated:YES];

但没有任何反应。

我的下一步是什么?

谢谢,

2 个答案:

答案 0 :(得分:0)

确保您的Controller实现MKMapViewDelegate并将MKMapView的委托设置为控制器。

答案 1 :(得分:0)

您必须使用MKMapView委托方法,如下所示,以识别您的iCodeBlogAnnotation

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    id <MKAnnotation> annotation = [view annotation];
    if ([annotation isKindOfClass:[iCodeBlogAnnotation class]])
    {
        iCodeBlogMapDetailViewController *dvc = [[iCodeBlogMapDetailViewController alloc] init];
        [self.navigationController pushViewController:dvc animated:YES];        
    }
}

让我知道,如果你让它工作

相关问题