2013-05-12 1 views
1

UITapGestureRecognizer를 사용하여 ImageviewTap 작업을 처리합니다. 주된 ViewController에서는 훌륭하게 작동합니다. 하지만 내 APP에서 다른 ViewController를 사용하고 동일한 UITapRecognizer 코드를 복사 할 때 EXC_BAD_ACCESS 코드 = 1 주소를 얻습니다 : 0x80759d3a 내 이미지 뷰어에 인식기를 추가하면 줄에 오류 메시지가 표시됩니다. 내가 틀린 게 뭐야?UITapGestureRecognizer 오류, 이미지보기에 추가 할 때

내 이미지 뷰 : 그것은

UIImageView *live; 
live = [[UIImageView alloc]initWithFrame:CGRectMake(92, 230, 136, 100)]; 
live.image = [UIImage imageNamed:@"online.png"]; 
[live addSubview:onlineLabel2]; 
[live setUserInteractionEnabled:YES]; 
[self.view addSubview:live]; 
[super viewDidLoad]; 

작동하고 내 제스처 인식기 :

UITapGestureRecognizer *singleTaP3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onlineTap:)]; 
singleTaP3.numberOfTapsRequired = 1; 
singleTaP3.numberOfTouchesRequired = 1;  
[live addGestureRecognizer:singleTaP3]; 

과 마지막 줄은 내가 사고를 얻을.

+0

먼저 [super viewDidLoad]를 호출해야합니다. 처음에는 코드를 추가합니다. – danypata

답변

0

내 문제는 내 주요의 ViewController했다. 나는 새로운 viewcontroller를 잘못 호출했고, nullpointer를 얻는다. 재산에 들어가면 효과가 있습니다. 문제는 gesturetaprecognizer가 아닙니다.

0

실시간보기가 보존되지 않는 것처럼 들리므로 제스처를 추가하려고하면보기가 더 이상 존재하지 않습니다. 라이브 뷰를 인터페이스의 속성으로 기록하고 구현시 통합하십시오.

+0

시도해 보았지만 작동하지 않습니다. (같은 오류, 같은 줄 – tomeszmh

+0

- (void) viewDidLoad 메서드 및 인터페이스를 제공해 주실 수 있습니까? – Franck

+0

[link] http://pastebin.com/mg1SeNf4 [link] http : //pastebin.com/5DTq7Egm – tomeszmh

0

나는이 것을 당신이 당신의 코드를 충돌의 원인이 확실하지 오전하지만 당신은 코드의 시작

[super viewDidLoad]; 

를 호출해야합니다. (ARC를 사용하고 있다면 ARC를 사용하는 것이 좋습니다.)

[super viewDidLoad]; 
UIImageView *live; 
live = [[UIImageView alloc]initWithFrame:CGRectMake(92, 230, 136, 100)]; 
live.image = [UIImage imageNamed:@"online.png"]; 
[live addSubview:onlineLabel2]; 
[live setUserInteractionEnabled:YES]; 
[self.view addSubview:live]; 
+0

ARC를 사용하지만 작동하지 않습니다. – tomeszmh

+0

ARC를 사용하는 경우 다음과 같이 속성을 선언해야합니다 (강력 함, 보유하지 않음). @ property (비 원자력, 강함) UIImageView * live; – Franck

+0

property @ 속성 (비 원자력, 강함) UIImageView * live; 및 _liv에 gesturerecognizer 추가 e, 같은 오류 – tomeszmh

0

다음 테스트를 통해 작동합니다. 인터페이스 :

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController 

@property (strong, nonatomic) UIView *v; 

- (void)tapAction; 

@end 

및 구현 :

#import "ViewController.h" 

@implementation ViewController 

@synthesize v=_v; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    _v = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)]; 
    [_v setBackgroundColor:[UIColor redColor]]; 

    [self.view addSubview:_v]; 

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)]; 
    tap.numberOfTouchesRequired = 1; 
    tap.numberOfTapsRequired = 1; 

    [_v addGestureRecognizer:tap]; 
} 

- (void)tapAction 
{ 
    NSLog(@"tap tap"); 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 
관련 문제