【发布时间】:2014-08-16 22:43:16
【问题描述】:
到目前为止,我的情节提要中有一个 DetailViewController ,没有转接/转接。这是我在地图视图控制器中的代码...
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"User"];
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];
MyPin.rightCalloutAccessoryView = rightButton;
MyPin.draggable = NO;
MyPin.highlighted = YES;
MyPin.animatesDrop=TRUE;
MyPin.canShowCallout = YES;
UIImageView *myCustomImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CorgiRunner2 Final.png"]];
myCustomImage.image = profPic;
myCustomImage.frame = CGRectMake(0,0,31,31);
MyPin.leftCalloutAccessoryView = myCustomImage;
[rightButton addTarget:self action:@selector(pinTouched:) forControlEvents:UIControlEventTouchUpInside];
return MyPin;
}
-(void)pinTouched:(UIButton *)sender
{
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
detailViewController.profName1 = profName;
detailViewController.profPic1 = profPic;
}
我怎样才能在按下调用时显示我的详细视图控制器?
【问题讨论】:
-
请注意:到目前为止,您的所有问题都已被 SO 上的其他用户多次询问和回答。在发布可能重复的问题之前,请在 SO、文档和其他地方彻底搜索(并且再次重新发布您自己的问题也不是一个好方法——改为编辑您现有的问题并解释为什么发布的答案对您不起作用)。
-
对于您当前的问题,请参阅stackoverflow.com/questions/14805954/… 以获取示例。
-
顺便说一句,如果你要使用内置委托方法 calloutAccessoryControlTapped,请不要使用 addTarget。如果您设置了附件视图并且设置了它的委托,则地图视图将自动调用其委托方法。
标签: ios objective-c annotations callout