【问题标题】:trying to push a detail view when the right button is tapped on the annotation of mapview in xcode当在 xcode 中的 mapview 注释上点击右键时,尝试推送详细视图
【发布时间】:2012-03-07 22:46:11
【问题描述】:

我想在 xcode 中点击 mapview 注释上的右键后显示详细视图,但我无法显示视图, 我的代码:

- (void)showDetails:(id)sender
{
  [self.navigationController setToolbarHidden:YES animated:NO];

[self.navigationController pushViewController:self.detailViewController animated:YES];

}



- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString* BridgeAnnotationIdentifier = @"bridgeAnnotationIdentifier";

MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
                                       initWithAnnotation:annotation reuseIdentifier:BridgeAnnotationIdentifier] autorelease];
customPinView.pinColor = MKPinAnnotationColorPurple;
customPinView.animatesDrop = YES;
customPinView.canShowCallout = YES;

UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
NSLog(@"%@",rightButton);
[rightButton addTarget:self
                action:@selector(showDetails:)
      forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
return customPinView;//[kml viewForAnnotation:annotation];
}

showDetails 方法被调用,但无法将 detailViewController 推到顶部,

[self.navigationController pushViewController:self.detailViewController animated:YES];

这段代码应该已经将详细视图推到顶部并显示了详细视图,但它不喜欢,

任何帮助将不胜感激,我想做的是当有人点击地图视图上注释的右侧按钮时,我想显示一个详细视图,提前谢谢你..

【问题讨论】:

标签: xcode mkmapview pushviewcontroller mkannotationview mkpinannotationview


【解决方案1】:

不需要目标/操作,当点击标注附件视图时会调用一个委托方法:mapView:annotationView:calloutAccessoryControlTapped:

【讨论】:

  • 好的,我有一个 detailViewController 如何在点击右键时显示​​该视图。
【解决方案2】:

感谢您的帮助,我可以通过更改 showDetails 方法打开 detailViewController

- (void)showDetails:(id)sender
    {
      detailViewController *dvController = [[detailViewController alloc] initWithNibName:nil bundle:nil];
      [self presentModalViewController:dvController animated:YES];
      [dvController release];
      dvController = nil;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-20
    • 1970-01-01
    • 2013-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-16
    相关资源
    最近更新 更多