2012-02-21 5 views
1

사용자가 iPhone 화면에서 터치했는지 감지해야했습니다. 그래서, 난 내 프로젝트 (하위 클래스 UIApplication)의 "CustomApplication"라는 이름의 클래스를 생성 한 후, I는 다음과 같이 내 main.m 수정 :- (void) sendEvent : (UIEvent *) 이벤트 메소드 iPhone 5.0

는이 클래스 "CustomApplication.m는"방법을 포함

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 
int retVal = UIApplicationMain(argc, argv, @"CustomApplication",nil); 
[pool release]; 
return retVal; 
다음과 같이를 :

- (void)sendEvent:(UIEvent *)event { 
[super sendEvent:event]; 
[MyUtility showAlertWithTitle:@"Alert!!!!" message:@"Session Expired!!!!"]; // showing an alert here 
} 

[방법] showAlertWithTitle은 다음과 같습니다

+ (void) showAlertWithTitle:(NSString *)aTitle message:(NSString *)aMessage 
{ 
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:aTitle message:aMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
[alertView show]; // Line causing problem in iOS 5 - base sdk 5.0 
[alertView release]; 

}

iOS 4.2에서는 모든 것이 잘 작동하지만 iOS 5.0에서는 앱을 사용하면 화면을 터치 할 때 충돌이 발생합니다 (sendEvent : event 메서드가 호출 될 때). 코드를 디버깅 할 때 문제가 [alertView show]에 있음을 발견했습니다. 선. iOS 5에서이 특정 라인 ([alertView show];)이 실행되면 CustomApplication의 sendEvent 메소드가 다시 호출되고이 메소드는 myUtility의 showAlertWithTitle : 메소드를 호출하며이 메소드는 다시 sendEvent 메소드를 호출하므로 코드 무한 루프에 들어가고 있습니다. 나는 해답을 모른다. 누군가가이 유령과 마주 쳤을 경우, 경고를 표시 할 때 sendEvent 메소드가 호출되지 않도록 내가 작성해야 할 내용을 알려주십시오.

+1

당신이'[alertView 쇼] 스택 추적을 포함 할 수 있습니다;'sendEvent를 호출을? – picciano

답변

1

이것은 최상의 접근 방식처럼 보이지 않을 수도 있지만 작동 할 수 있습니다. 함수에 다시 호출되지 않도록 코드에 정적 부울 변수를 포함 시키려고 했습니까? 최대

BOOL stopHere = NO; 

그리고

어딘가에 다음 sendEvent

-(void)sendEvent:(UIEvent *)event{ 
    [super sendEvent:event]; 
    if (!skipHere){ 
     skipHere = YES; 
     [MyUtility showAlertWithTitle:@"Alert!!!!" message:@"Session Expired!!!!"]; // show   
    skipHere=NO; 
    } 
    } 
관련 문제