【发布时间】:2010-08-16 18:32:19
【问题描述】:
我只想实现一个小功能,允许系统获取用户触摸的MKMapView 上的位置。我写了一些代码如下:
#import "UIViewTouch.h"
@implementation UIViewTouch
@synthesize viewTouched;
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *) event{
NSLog(@"Hit Test");
NSLog(@"x = %f, y = %f", point.x, point.y);
MKMapView *mapView = (MKMapView *) [self.subviews objectAtIndex:0];
CLLocationCoordinate2D coordinate = [mapView convertPoint:point toCoordinateFromView:self];
NSLog(@"Lat = %f, Lng = %f", coordinate.latitude,coordinate.longitude);
//MapAnnotation is a custom class and confirms to MKAnnotation.
MapAnnotation *annotation = [[MapAnnotation alloc] initWithCoordinate:coordinate];
[mapView addAnnotation:annotation];
return [super hitTest:point withEvent:event];
}
- (BOOL) pointInside:(CGPoint)point withEvent:(UIEvent *)event{
return [super pointInside:point withEvent:event];
}
@end
如果我不在MKMapView上加注解也可以正常工作,否则app会抛出异常:
由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'-[TESTViewController openCallout:]: 无法识别的选择器发送到实例 0x6b60180'
有什么想法吗?
非常感谢!
【问题讨论】: