2012-07-10 2 views
5

iOS 앱을 작성 중이며 회 전자와 함께 UIAlertView를 표시해야합니다. 간혹 일 때 경고의 중심에 회 전자를 추가하려고 할 때 뭔가 잘못됩니다. 일반적으로이 경고 바로 앞에 다른 경고가있을 때 (정확히는 규칙이 아니지만 이것이 실패한 것으로 나타났습니다).UIAlertView에서 UIActivityIndicatorView가 올바르게 표시되지 않습니다.

나는 스피너 생성을 지연시킴으로써 부분적으로이 버그를 해결했다.

이 코드가있는 viewDidLoad에 있습니다 : 여기가 어떻게입니다 (경고는 회원 UIAlertView입니다)

alert = [[[UIAlertView alloc] initWithTitle:@"Loading..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil] autorelease]; 

[alert show]; 

[self performSelector:@selector(addSpinner) withObject:nil afterDelay:0.5f]; 

는 그리고이 사람은 내 addSpinner 기능입니다 :

- (void) addSpinner{ 

    UIActivityIndicatorView *indicator2 = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 

    indicator2.center = CGPointMake(alert.bounds.size.width/2, alert.bounds.size.height - 50); 

    [indicator2 startAnimating]; 
    [alert addSubview:indicator2]; 
    [indicator2 release]; 
} 

이 솔루션은 매번 작동하지만 실제로 완료되는 방식을 싫어합니다. 경보가 울린 후 0.5 초가 지나면 회 전자를 보이더라도 방해가되는 것은 아니지만이를 처리 할 수있는 더 좋은 방법이 있어야합니다. 나는 IOS의 전문가가 아니며 수석 프로그래머도 아니지만 이벤트를 사용할 수 없습니까? "경고가 실제로 표시 될 때 addSpinner 함수로 이동"과 같은 것입니까? 나는 이것을 어떻게하는지 잘 모른다. 그리고 웹상에서 많은 도움을 찾을 수 없었다 ...

누군가 나를 도울 수 있기를 희망한다! 감사.

답변

5

대신 https://github.com/jdg/MBProgressHUD을 사용할 수 있습니다.

및 경고 내 회 전자의 경우 이러한 방법을 사용할 수 있습니다.

-(void)startLoading 
{ 
    alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Wait..." delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; 

    UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)]; 
    progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; 
    [alert addSubview:progress]; 
    [progress startAnimating]; 
    [progress release]; 
    [alert show]; 
} 
-(void)stopLoading 
{ 
    [alert dismissWithClickedButtonIndex:0 animated:YES]; 
    [alert release]; 
} 
+0

고마워. 사용해볼 수 있습니다. 나는 그것이 실제로 문제를 해결하지 않기 때문에 나의 "받아 들인 대답"으로 대답을 표시 할 수 없다 :) – rdurand

+1

아무런 이슈 :) .. 도움이된다면 당신은 그냥 투표 할 수있다. :) – waheeda

+1

나는 문제를 해결하기위한 코드가 도움이되기를 바랍니다. – waheeda

2

사용하는 표시를 닫으려면이 코드를이

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; 
megaAlert = [[[UIAlertView alloc] initWithTitle:@"Please wait..." 
                 message:nil delegate:self cancelButtonTitle:nil 
               otherButtonTitles: nil] autorelease]; 
[megaAlert show]; 
indicator = [[UIActivityIndicatorView alloc]              initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
      indicator.center = CGPointMake(megaAlert.bounds.size.width/2,           megaAlert.bounds.size.height - 45); 
[indicator startAnimating]; 
[megaAlert addSubview:indicator]; 
[indicator release]; 

을 시도

[megaAlert dismissWithClickedButtonIndex:0 animated:YES]; 
megaAlert = nil; 
[indicator stopAnimating]; 
+0

감사합니다.이것은 기본적으로 경고를 기각하지 않고 처음부터 내가 한 일입니다. UIActivityIndicator의 위치에 영향을 줄 수 있다고 생각합니까? 몇 분 안에 작동하는지 알려 드리겠습니다. – rdurand

+0

실제로 UIAlertView가 표시되기 전에 UIActivityIndicator의 위치가 설정되기 때문에 문제가 나타나는 것으로 보입니다. 경고를 무시하면이 문제가 해결 될 것이라고 생각하지 않습니다 ... – rdurand

1

메인 스레드에서 경보 해제도 기억

dispatch_async(dispatch_get_main_queue(), ^{ 
    [self.alert dismissWithClickedButtonIndex:0 animated:YES]; 
}); 
4

은 기본적으로 문제가 외모를 UIAl 앞에 UIActivityIndicator를 추가해야합니다. ertView가 표시됩니다. UIAlertView Delegate 메서드를 사용하여 아래와 같이 인디케이터를 추가하십시오.

//AlertView delegate methods 
- (void)didPresentAlertView:(UIAlertView *)alertView 
{ 
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; 

    indicator.center = CGPointMake(alertView.bounds.size.width/2, alertView.bounds.size.height/3 * 2); 

    [indicator startAnimating]; 
    [alertView addSubview:indicator]; 
} 
+1

늦게 답변 해 주셔서 감사합니다. 문제가 해결 될 수도 있지만 MBProgressHUD를 사용함에 따라 더 이상 문제가 발생하지는 않습니다. – rdurand

관련 문제