你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS UIAlertView中UIActivityindicatorView風火輪提示加載等待

iOS UIAlertView中UIActivityindicatorView風火輪提示加載等待

編輯:IOS開發綜合

 

1、SignInViewController.h

 

#import 

@interface SignInViewController : UIViewController{
    UIAlertView *remoteAlertView;
}
@end

 

2、SignInViewController.m

 

#import SignInViewController.h

@interface SignIniewController ()

@end

@implementation SignInViewController


-(void)dealloc{
    if (remoteAlertView) {
        [remoteAlertView release];
    }
    [super dealloc];
}


// 方法內:
    // 遠程webservice方法
    RemoteLogic *remoteLogic = [[RemoteLogic alloc] init];
    // 啟動動畫
    [self remoteAnimation:@正在獲取服務器時間, 請稍候...];
    // 異步加載數據
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 獲取webservice數據
        delegate.serverTime = remoteLogic.getServerTime;
        dispatch_async(dispatch_get_main_queue(), ^{
            // 關閉動畫
            [remoteAlertView dismissWithClickedButtonIndex:0 animated:YES];
            // 獲取webservice數據後操作 do something
        });
    });



#pragma mark - Animation
-(void)remoteAnimation:(NSString *)message{

    if (remoteAlertView) {
        [remoteAlertView release];
    }
    remoteAlertView =  [[UIAlertView alloc] initWithTitle:@提示 message:message delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil ];
    UIActivityIndicatorView *aiView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125.0, 80.0, 30.0, 30.0)];
    aiView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    //check if os version is 7 or above. ios7.0及以上UIAlertView棄用了addSubview方法
    if ([[[UIDevice currentDevice] systemVersion] compare:@7.0] != NSOrderedAscending) {
        [remoteAlertView setValue:aiView forKey:@accessoryView];
    }else{
        [remoteAlertView addSubview:aiView];
    }
    [remoteAlertView show];
    [aiView startAnimating];
    [aiView release];
}

3、效果ios5.1,ios7.1.2

 

\

\

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved