我发现如何将标题和字幕推送到DVcontroller而不是图片。我想在点击详细信息披露按钮时将特定图片的注释推送到新的DV。 (使用Xcode5)
我有2个VC的故事板设置,第一个嵌入在Nav控制器中。引脚显示在地图上(NSMutable数组),标注右侧显示详细信息显示按钮(左侧显示按钮以供将来使用)。来自详细信息披露按钮的segue工作,因为我可以在点击它时看到DVcontroller上的蓝色背景屏幕。我导入了图片文件并将它们与每个注释相关联。
我相信答案是在“calloutAccessoryControlTapped”方法中。我在该方法中尝试了几个代码,但仍无法在DVcontroller中返回图片。
ViewController.m如下:
(每个注释都设置如下):
//Chateau l'Evesque annotation
myAnn = [[myAnnotation alloc] init];
location.latitude = CLEVESQUE_LATITUDE;
location.longitude = CLEVESQUE_LONGITUDE;
myAnn.coordinate = location;
myAnn.title = @"Château l'Evesque";
myAnn.imageView=[UIImage imageNamed:@"Château l'Evesque"];
[locations addObject:myAnn];
(然后是viewForAnnotation方法):
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:
(id<MKAnnotation>)annotation
{
if([annotation isKindOfClass: [MKUserLocation class]]) return nil;
static NSString *reuseId = @"myAnn";
MKAnnotationView *customAnnotationView = [mapView
dequeueReusableAnnotationViewWithIdentifier:reuseId];
if (customAnnotationView == nil)
{
myAnnotation *myAnn = (myAnnotation *)annotation;
}
MKPinAnnotationView *Mypin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"current"];
Mypin.pinColor = MKPinAnnotationColorPurple;
UIButton *directionButton = [UIButton buttonWithType:UIButtonTypeCustom];
directionButton.frame = CGRectMake(0, 0, 23, 23);
[directionButton setBackgroundImage:[UIImage imageNamed:@"PetitVolant.png"]
forState:UIControlStateNormal];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
Mypin.leftCalloutAccessoryView = directionButton;
Mypin.rightCalloutAccessoryView = infoButton;
Mypin.draggable = NO;
Mypin.highlighted = YES;
Mypin.animatesDrop = TRUE;
Mypin.canShowCallout = YES;
return Mypin;
}
(然后是罪魁祸首):
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
myAnnotation *myAnn = (myAnnotation *)view.annotation;
NSLog(@"myAnn.imageView = %@",myAnn.imageView);
[self performSegueWithIdentifier:@"ShowPhotoSegue" sender:self];
}
(我对“prepareForSegue”方法进行了绿化,因为到目前为止它没有改变任何结果。)
我改写了整个事情。仍然是同样的问题。我将尝试更好地解释这个问题。我只想将图片(.png文件)推送到下一个视图控制器。点击详细信息显示按钮后,我只在Detail VC上显示一个空白(白色)屏幕。
如果我包含以下prepareForSegue
方法(如建议的帖子中所述):
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"ToDetail"])
{
MKAnnotationView *annotationView = sender;
[segue.destinationViewController setAnnotation:annotationView.annotation];
我收到以下错误:
GuideDesVinsCPA[2523:70b] myAnn.imageForMyAnnotation = <UIImage: 0x9a4f510>
GuideDesVinsCPA[2523:70b] -[MapViewController annotation]: unrecognized selector sent to instance 0x9f31970
GuideDesVinsCPA[2523:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MapViewController annotation]: unrecognized selector sent to instance 0x9f31970'