【问题标题】:Detail view on Map in Iphone SDKIphone SDK 中地图的详细视图
【发布时间】:2013-01-23 12:22:50
【问题描述】:

在我的应用中,我实现了地图视图并添加了注释。

但是现在,我想在弹出窗口中显示单击注释的详细视图。到目前为止,我是在单击 calloutAccessoryControl 时执行此操作的。

但弹出框必须从注释 & 旁边开始 我不想显示 calloutAccessoryControl 或任何黑色默认标签。

我的代码是:

- (MKAnnotationView *)mapView:(MKMapView *)myMap viewForAnnotation:(id <MKAnnotation>)annotation
{
AnnotationImageView *myLocationImage = (AnnotationImageView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultID];

    if (myLocationImage == nil )
    {
        myLocationImage = [[[AnnotationImageView alloc] initWithAnnotation:annotation reuseIdentifier:defaultID] autorelease];
        myLocationImage.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];     
    }

    myLocationImage.locationID = [currentAnnotation locationID];
    myLocation = myLocationImage;

    [myLocation setEnabled:YES];
    [myLocation setCanShowCallout:YES]; 

    return myLocation;
}


- (void)mapView:(MKMapView *)myMap annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{

detailsView *popUp=[[detailsView alloc] initWithNibName:@"detailsView_ipad" bundle:nil];


        popView = [[UIPopoverController alloc]initWithContentViewController:popUp];

        popView.delegate =self;

        [popView setPopoverContentSize:CGSizeMake(600, 500)];



AnnotationImageView *myLocationImage = (AnnotationImageView *)view;
        popUp.locationID = myLocationImage.locationID;

[popView presentPopoverFromRect:control.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

}

点击注解时是否有方法调用?

我该怎么做?

** 我想这样展示**

【问题讨论】:

    标签: iphone ios objective-c xcode mkmapview


    【解决方案1】:

    在实现MKMapViewDelegate 的类中,您可以实现mapView:didSelectAnnotationView: 方法:

    - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)aView {
        //do something...like push a new UIViewController
    
        if (UIUserInterfaceIdiomPhone == UI_USER_INTERFACE_IDIOM()) {
            //only do something when the app is running on the iPhone
        }
    }
    

    【讨论】:

    • 感谢您的回复!但是很抱歉,您的方法没有被调用。
    • 您可以使用UIUserInterfaceIdiomPhone == UI_USER_INTERFACE_IDIOM()检查应用程序是否在Phone或Pad上运行。您可以在mapView:didSelectAnnotationView: 的实现中设置这样的if 子句。 iPhone 上的空实现应该没问题。
    • 你能发布一些代码来调用这个方法吗?我不知道这个。
    • 该方法应该被调用,我用一个新项目测试过。请在方法的开头添加NSLog(@"..."); 语句。请查看 MKMapViewDelegate 协议参考以查看方法的描述。还要检查您是否将 MKMapView 实例的 delegate 设置为正确的类(在 Interface Builder 或代码中:例如:_myMapView.delegate = self)。
    • 应该在 NSLog 中打印什么,我试过了,但没有调用你的方法。
    猜你喜欢
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-10
    • 2012-08-10
    • 2012-10-04
    • 1970-01-01
    相关资源
    最近更新 更多