2012-10-27 1 views
0

제목에서 단추가 특정 양의 탭을 수신 한 후에 경고 메시지를 표시하는 방법을 알아 내려고합니다. 지금까지 필자수신 된 탭 수 후에 경고보기를 표시하는 방법

- (IBAction)count:(id)sender { 

{ 
    UITouch *touch = [count]; 
    if (touch.tapCount == 4) 
    { 
} 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"My alert text here" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil]; 

[alert show]; 

} 

} 

위의 밤은 가공을 마련, 필자는 작업으로 내 버튼 count을 설정 및 출구 counted

답변

2

로 그 코드는 많은 이해가되지 않습니다 (나는 놀랐어요 그것은 컴파일, 그렇지?). UITouch는 버튼을 선택할 때 포함되지 않습니다. 당신이해야 할 일은 버튼을 몇 번 누른 횟수를 유지하고 그것을 인스턴스 변수로 저장하는 것입니다.

static int numberTouches; 

그리고 (viewWillAppear에서) 어딘가에 설정 : (구현의) 예를 들어

:

@interface ClassName() { 
    NSUInteger m_buttonTouchCount; 
} 
@end 

// Set m_buttonTouchCount to 0 in your init/appear method, whenever it's appropriate to reset it 

- (IBAction)count:(id)sender { 
{ 
    m_touchButtonCount++ 
    if (m_touchButtonCount == 4) 
    { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" 
                 message:@"My alert text here" 
                 delegate:nil 
               cancelButtonTitle:@"Ok" 
               otherButtonTitles:nil]; 
     [alert show]; 
     m_touchButtonCount = 0; // Not sure if you want to reset to 0 here. 
    } 
} 
+0

아니요. 적어도 이드가 직접 해결하려고 노력한 것만 보여주는 컴파일은 없습니다. 위대한 작품에 도움을 주셔서 감사합니다! 이 코드가 필요한 다른 모든 사용자를 위해 NSUinteger'm_buttonTouchCount'를'm_touchButtonCount'로 변경해야했습니다. – JSA986

0

코드 정적 값의 시작에 어딘가에 정의

numberTouches을 = 0; 사용자가 다른 곳에서 녹화하면

- (IBAction)count:(id)sender { 
{ 
    numberTouches++; 
    if(numberTouches == 4) 
    { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"My alert text here" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil]; 
     [alert show]; 
    } 
} 

Remeber는이 작업을 수행 할 위치 viewDidDissapear 예를 들면, 장소에 numberTouches를 0으로 설정하거나하기 :보다

.

+0

나는 개인적으로'static int numberTouches;'를 사용하는 것을 삼가고 싶다. C의 유물이고 초보자에게는이 문맥에서 정적 사용은 혼란 스럽다. (클래스의 모든 인스턴스에서 전역적일 수있다. 현실은 변수에 파일 범위가 있음을 의미합니다). Obj-C 메서드는 속성 및 클래스 확장을 사용하는 방식을 통해 더 많이 사용됩니다. – WDUK

+0

@WDUK 감사드립니다. 설명이 정확합니다. – edzio27

관련 문제