단추로 사용자 정의 설명 선에 대한보기를 만들었습니다. 이 사용자 정의 콜 아웃은 Mapview의 모든 주석을 클릭하면 표시됩니다. 하지만 사용자 정의 콜 아웃 내부의 버튼을 클릭해도 아무런 변화가 없습니다.UIView 내부에서 IBAction이 호출되지 않습니다.
#import <UIKit/UIKit.h>
@interface TestView : UIView
@end
#import "TestView.h"
@implementation TestView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(IBAction)showMessage:(id)sender
{
NSLog(@"Test");
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
if(![view.annotation isKindOfClass:[MKUserLocation class]]) {
CGRect rect = CGRectMake(0,0,268,140);
TestView *testview = [[TestView alloc] initWithFrame:rect];
testview = [self loadNibNamed:@"TestView" ofClass:[TestView class]];
[view addSubview:testview];
}
}
뷰는 loadNibNamed 메소드를 사용하여로드됩니다.
- (id)loadNibNamed:(NSString *)nibName ofClass:(Class)objClass {
if (nibName && objClass) {
NSArray *objects = [[NSBundle mainBundle] loadNibNamed:nibName owner:nil options:nil];
for (id currentObject in objects){
if ([currentObject isKindOfClass:objClass])
return currentObject;
}
}
return nil;
}
나는보기와 버튼의 userInteractionEnabled 속성을 확인하고 모두 true로 설정되어 있습니다.
버튼의 내부 위로 터치 이벤트로 showMessage를 매핑했습니다.
이 문제를 식별하는 방법에 대한 제안 사항은 무엇입니까?
는 일반적인 오류는 단순히 IB 내에서 제대로 동작을 연결하지 않습니다. 그걸 확인해 봤어? – trojanfoe
감사합니다. 같은 스크린 샷이 포함되어 있습니다. – rshankar
방금 실수를 발견했습니다. [view addSubview : testview]; [mapView addSubview : testview]로 대체해야합니다. 도와 주셔서 감사합니다. – rshankar