2011-04-21 18 views
1

UISwipeGestureRecognizerDirectionRight 메서드를 사용하여 응용 프로그램 내에서보기를 변경하고 View Controller의 주 파일에서 다음 코드를 사용했지만 별표 뒤에 제스처를 정의하고 다음과 같이 선언해야합니다. 이 빌드 오류 상태 : "swipeGesture는 선언되지 않은"UITouchGestures 선언?

-(void)createGestureRecognizers { 
UISwipeGestureRecognizerDirectionRight * swipeGesture = [[UISwipeGestureRecognizerDirectionRight alloc] 
                 initWithTarget:self 
                 action:@selector (handleSwipeGestureRight:)]; 
[self.theView addGestureRecognizer:swipeGesture]; 
[swipeGesture release]; 
} 

-(IBAction)handleSwipeGestureRight { 
NC2ViewController *second2 =[[NC2ViewController alloc] initWithNibName:@"NC2ViewController" bundle:nil]; 
second2.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
[self presentModalViewController:second2 animated:YES]; 
[second2 release]; 

} 

그래서 내 질문에 내가 헤더 파일에 별표 후 "swipeGesture"을 선언 않거나 내가 뭔가 잘못을했을 어떻게?

당신

답변

1

UISwipeGestureRecognizerDirectionRight이 네 가지 방향에 대한 열거 값입니다 감사합니다. 제스처를 인식하기 위해 인스턴스화하는 클래스는 아닙니다. 대신 UISwipeGestureRecognizer를 사용 또한

UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] 
           initWithTarget:self 
           action:@selector (handleSwipeGestureRight:)]; 

//Set the direction you want to detect by setting 
//the recognizer's direction property... 
//(the default is Right so don't really need it in this case) 
swipeGesture.direction = UISwipeGestureRecognizerDirectionRight; 

[self.view addGestureRecognizer:swipeGesture]; 
[swipeGesture release]; 

은 핸들러 메소드가 있어야한다 :

-(IBAction)handleSwipeGestureRight:(UISwipeGestureRecognizer *)swipeGesture { 

작업에 대한 선택, 당신은 의미 메소드 이름에 콜론을 넣어 때문에 당신이 보낸 사람에게 전달하려는 첫 번째 매개 변수로 개체. (당신은 또한 당신이 핸들러에서 보낸 사람을 필요로하지 않는 대신하는 경우 선택기에서 콜론을 제거 할 수 있습니다.)이 객체에서 호출되지 않기 때문에

마지막으로, void 핸들러에서 IBAction보다 더 적합 a xib. 그러나 IBAction과 void는 동일한 것이기 때문에 문제가되지는 않습니다.

+0

감사합니다. 덕분에 많은 도움이되었습니다. :) – AppleFanBoy