我已经像这样实施了calloutAccessoryControlTapped
:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"calloutAccessoryControlTapped: annotation = %@", view.annotation.title);
if([_delegate respondsToSelector:@selector(mapView:didClickPinButton:)])
{
NSString *titleStr = [(DisplayMap *)view.annotation title];
[_delegate performSelector:@selector(mapView:didClickPinButton:)withObject:titleStr];
}
}
当我点击pin的按钮时,它会转到主视图控制器上的方法mapView:didClickPinButton
并显示错误:
线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x ......)
这是mapView:didClickPinButton:
方法:
- (void) mapView: (MapView *) mapView didClickPinButton:(NSString *) title
{
NSLog(@"bsn name-->%@",title);
for(int i=0;i<[self.categoryListArray count];i++)
{
NSMutableDictionary *couponDetail = [self.categoryListArray objectAtIndex:i];
if([[couponDetail objectForKey:@"category_name"] isEqualToString:title])
{
NSNumber *coupon_type=[couponDetail objectForKey:@"coupon_type"];
int c_type = [coupon_type intValue];
if(c_type == 1)
{
[self callServiceForCouponTypeOneBlock:[couponDetail objectForKey:@"id"] ];
break;
}
else if(c_type == 2)
{
BusinessViewController *businessVC = [[BusinessViewController alloc]initWithNibName:@"BusinessViewController" bundle:nil];
[businessVC setCouponListDetail:couponDetail];
[self.navigationController pushViewController:businessVC animated:YES];
break;
}
}
}
答案 0 :(得分:1)
问题在于这一行:
[_delegate performSelector:@selector(mapView:didClickPinButton:)withObject:titleStr];
performSelector:withObject:
方法只能用于调用 一个 对象参数的方法,但您的mapView:didClickPinButton:
方法 两个 对象参数。
您可以而是使用performSelector:withObject:withObject:
,它允许您使用两个对象参数调用方法,如下所示:
[_delegate performSelector:@selector(mapView:didClickPinButton:)
withObject:mapView withObject:titleStr];
但是,在这里使用performSelector
似乎并不是必需的。
直接在委托上调用方法会更容易也更简单,因此方法有多少参数无关紧要:
[_delegate mapView:mapView didClickPinButton:titleStr];