码迷,mamicode.com
首页 > 移动开发 > 详细

iOS UIAlertView中UIActivityindicatorView风火轮提示加载等待

时间:2014-08-11 17:59:52      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:uialertview   uiactivityindicatorv   风火轮   加载等待   小菊花   

参考:http://stackoverflow.com/questions/18729220/uialertview-addsubview-in-ios7

1、SignInViewController.h

#import <UIKit/UIKit.h>

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

2SignInViewController.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

bubuko.com,布布扣

bubuko.com,布布扣

iOS UIAlertView中UIActivityindicatorView风火轮提示加载等待,布布扣,bubuko.com

iOS UIAlertView中UIActivityindicatorView风火轮提示加载等待

标签:uialertview   uiactivityindicatorv   风火轮   加载等待   小菊花   

原文地址:http://blog.csdn.net/fengshi_sh/article/details/38493829

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!