2012-07-12 1 views
2

임 사용하여 경고보기와 작업 표시기를 표시 :경고보기 작동 표시 등 표시 시간

UIAlertView *Alert= [[UIAlertView alloc] initWithTitle:@"Loading" 
               message:@"\n" 
               delegate:self 
            cancelButtonTitle:nil 
            otherButtonTitles:nil]; 

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
spinner.center = CGPointMake(139.5, 75.5); 
[Alert addSubview:spinner]; 
[spinner startAnimating]; 
[Alert show];  

[Alert dismissWithClickedButtonIndex:0 animated:YES]; 

유일한 것은 그것이 내가 경고가 켜져있는 시간을 지정하고 싶은 진짜 빠른 화면 밖으로 사라집니다 스크린은 지금 표시된 나노 초가 아니라 2 초라고 말합니다. 임 진행 방법에 대해 확신 할 수 없거나 이것을 구현할 때 어떤 종류의 NSTimer를 사용하겠습니까? 그렇다면이를 구현하는 방법에 대한 조언이 있으면 대단히 감사하겠습니다. 감사.

+0

일반적으로 회 전자를 표시하는 것은 작업을 수행했기 때문입니다. 작업이 완료 될 때마다 회피하도록 설정하지 않으시겠습니까? 아니면 정말로 시간을 맞추고 싶습니까? 2 초가되기를 원하면'NSTimer'를 사용하십시오. 내가 왜 당신이 경고보기를 표시하고 즉시 밀리 초 디스플레이와 다른 결과가 될 것이라고 해산 생각하지 않을거야 ... –

+0

트위터 프레임 워크를 사용하여 응용 프로그램에서 트윗을 할 때 theres 약 2 지연 될 것으로 보인다 버튼을 누르는 순간부터 표시되는 트위터 시트까지 3 초. Alert View (경보보기)는 2.5 초 동안 약 5 초간 표시됩니다. 'timer = [NSTimer scheduledTimerWithTimeInterval : (1.2/2.0) target : 셀렉터 : @selector (로드 중) userInfo : nil repeats : YES]; '던져진 예외가 생겨서 작업을 시도하고 있습니다. – JSA986

+0

여전히 카운터처럼 직관적 인 것처럼 보입니다. 지연 시간 동안 경고보기를 표시해야하는 지연을 가정해서는 안됩니다. 그것이 그 주 목적입니다. 정보를받은 후에는 퇴장을 장소에 배치 할 수 있어야합니다. –

답변

1

다음은 NSTimerNSInvocation을 사용하여 문제를 해결하는 방법에 대한 예입니다. 나는 그것을 테스트하지 않았으므로 그것에 약간의 문제가있을 수 있습니다.

UIAlertView *Alert= [[UIAlertView alloc] initWithTitle:@"Loading" 
               message:@"\n" 
               delegate:self 
            cancelButtonTitle:nil 
            otherButtonTitles:nil]; 
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
spinner.center = CGPointMake(139.5, 75.5); 
[Alert addSubview:spinner]; 
[spinner startAnimating]; 
[Alert show]; 
NSMethodSignature *mySignature = [UIAlertView instanceMethodSignatureForSelector:@selector(dismissWithClickedButtonIndex:animated:)]; 
NSInvocation *myInvocation = [NSInvocation invocationWithMethodSignature:mySignature]; 
[myInvocation setSelector:@selector(dismissWithClickedButtonIndex:animated:)]; 
[myInvocation setTarget:Alert]; 
int buttonIndex = 0; 
bool isAnimated = YES; 
[myInvocation setArgument:&buttonClicked 
        atIndex:2]; 
[myInvocation setArgument:&isAnimated 
        atIndex:3]; 
NSTimer *t = [NSTimer scheduledTimerWithTimeInterval:2 
              invocation:myInvocation 
              repeats:NO]; 

여전히이 질문에 대한 최선의 대답이라고 생각하지 않습니다. 대부분의 경우 시간을 기준으로하지 않고 작업이 완료 될 때까지 표시기를 사용해야합니다 (특히 다른 요소에 따라 달라 지거나 변경 될 수있는 시간이 아님).

따라서 작업이 완료 될 때까지 올바른 대답을 기다리고 그 시점에서 UIAlertView을 닫으십시오.

+0

감사합니다, 페니는 이제 행동 후 해고와 함께 지금도 프로그래밍으로 내 길을 찾는 데 도움이 주셔서 감사합니다, 나는 당신의 조언에 따라 올바른 방법으로 그것을 할 것입니다. – JSA986