Indicator.h
//
// IndicatorClass.h
#import <Foundation/Foundation.h>
@interface IndicatorClass : NSObject
{
UIView *_loadingView;
UIActivityIndicatorView *_indicator;
UILabel *_label;
}
- (void)accessStart :(UIView *) _uiview WithWord:(NSString*) word;
- (void)accessEnd;
@property (nonatomic, retain) UIView *loadingView;
@property (nonatomic, retain) UIActivityIndicatorView *indicator;
@property (nonatomic, retain) UILabel *label;
@end
Indicator.m
//
// IndicatorClass.m
#import "IndicatorClass.h"
@implementation IndicatorClass
@synthesize loadingView = _loadingView;
@synthesize indicator = _indicator;
@synthesize label = _label;
- (void)accessStart :(UIView *) _uiview WithWord:(NSString*) word
{
//インジケータON(画面中央)
_loadingView = [[UIView alloc] initWithFrame:[_uiview bounds]];
[_loadingView setBackgroundColor:[UIColor blackColor]];
[_loadingView setAlpha:0.5];
_indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[_loadingView addSubview:_indicator];
[_indicator setFrame:CGRectMake ((320/2)-20, (480/2)-60, 40, 40)];
[_indicator startAnimating];
_label = [[UILabel alloc] initWithFrame:CGRectMake((320/2)-50, (480/2)-10,100,30)];
_label.backgroundColor = [UIColor clearColor];
_label.text = word;
[_loadingView addSubview:_label];
[_uiview addSubview:_loadingView];
}
- (void)accessEnd
{
// 画面中央の処理中インジケータ表示OFF
[_indicator stopAnimating];
[_loadingView removeFromSuperview];
[_label removeFromSuperview];
}
- (void)dealloc
{
_loadingView = nil;
_indicator = nil;
_label = nil;
[super dealloc];
}
@end
実行ファイル
- (void)main
{
[_indicator accessStart:self.view WithWord:@"更新中..."];
[self performSelectorInBackground:@selector(insertViewData) withObject:nil];
}
- (void)insertViewData
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//重たい処理
[_indicator accessEnd];
[pool release];
}