http://agilewarrior.wordpress.com/2012/04/03/how-to-display-uiactivityindicatorview-spinner-for-long-running-operations/
쓰레드 값을 주어 마치 indicatior 가 움직이게 처리하는 것이라 착각하게 만듬.
#import "rcsViewController.h"
@implementation rcsViewController
@synthesize myLabel;
@synthesize myButton;
- (IBAction)process:(id)sender {
// replace right bar button 'refresh' with spinner
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = CGPointMake(160, 240);
spinner.hidesWhenStopped = YES;
[self.view addSubview:spinner];
[spinner startAnimating];
// how we stop refresh from freezing the main UI thread
dispatch_queue_t downloadQueue = dispatch_queue_create("downloader", NULL);
dispatch_async(downloadQueue, ^{
// do our long running process here
[NSThread sleepForTimeInterval:10];
// do any UI stuff on the main UI thread
dispatch_async(dispatch_get_main_queue(), ^{
self.myLabel.text = @"After!";
[spinner stopAnimating];
});
});
dispatch_release(downloadQueue);
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[self setMyLabel:nil];
[self setMyButton:nil];
[super viewDidUnload];
}
@end
'개발도구 > iOS - 아이폰 개발' 카테고리의 다른 글
[ios] 아이폰 생명주기 사이클 (0) | 2012.09.28 |
---|---|
[아이폰] NSUserDefault -> NSMutableArry (0) | 2012.09.24 |
[MAC 맥] 동영상 인코딩, 동영상 인코더 (0) | 2012.09.23 |
[맥] 맥 과 윈도우즈 공유하기 (0) | 2012.09.20 |
[맥 mac] paralles windows7 한글깨짐 (0) | 2012.09.20 |