单例Singleton。

#import <UIKit/UIKit.h>

@interface CommonLoadingViewController : NSObject
{
    UIActivityIndicatorView *LoadingView;
    UIView  *backgroundView;
}
-(void)loadingView;
-(void)finishedLoading;
+ (CommonLoadingViewController*)sharedLoading;
@end
#import "CommonLoadingViewController.h"
#import "GenericAppDelegate.h"
#import "KDesign.h"


@implementation CommonLoadingViewController

static CommonLoadingViewController *sharedGizmoManager = nil;

//___________________________________________________________________________
+ (CommonLoadingViewController*)sharedLoading
{
    if (sharedGizmoManager == nil) {
        sharedGizmoManager = [[super allocWithZone:NULL] init];
    }
    return sharedGizmoManager;
}

//___________________________________________________________________________
+ (id)allocWithZone:(NSZone *)zone
{
    return [[self sharedLoading] retain];
}

//___________________________________________________________________________
- (id)copyWithZone:(NSZone *)zone
{
    return self;
}

//___________________________________________________________________________
- (id)retain
{
    return self;
}

//___________________________________________________________________________
- (NSUInteger)retainCount
{
    return NSUIntegerMax;  //denotes an object that cannot be released
}

//___________________________________________________________________________
- (id)autorelease
{
    return self;
}

//___________________________________________________________________________
-(void)loadingView{

    backgroundView = [[UIView alloc] init];
    backgroundView.frame = CGRectMake(0, 0,kWidth,kHeight);
    backgroundView.backgroundColor = [UIColor colorWithRed:(40/255.0f) green:(40/255.0f) blue:(40/255.0f) alpha:1.0f];
    backgroundView.alpha = 0.4;
    [[getDelegate window] addSubview:backgroundView];

    LoadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [LoadingView setCenter:CGPointMake(kWidth/2, kHeight/2 - 40)];
    LoadingView.hidesWhenStopped = YES;
    //LoadingView.color = [UIColor grayColor];
    LoadingView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;

    [backgroundView addSubview:LoadingView];
    [viewController.view.window bringSubviewToFront:backgroundView];
    [LoadingView startAnimating];

}



//___________________________________________________________________________
-(void)finishedLoading{
    [LoadingView stopAnimating];
    [LoadingView removeFromSuperview];
    [backgroundView removeFromSuperview];
}

#pragma mark -
#pragma mark Memory management
//___________________________________________________________________________
- (void)dealloc {
    [backgroundView release];
    [LoadingView release];
    [super dealloc];
}

@end


备注:

网上有很多单例的例子。不过大部分都是只有实现部分的。

这是我写的关于loading界面的一个单例。

如有不好请指正。

调用的时候:

#define getCommonLoading [(GenericAppDelegate *)[[UIApplication sharedApplication] delegate] commonLoading]
commonLoading = [CommonLoadingViewControllersharedLoading];//重复调用放到appdelegate里面
[getCommonLoading   loadingView];
[getCommonLoading   finishedLoading];


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值