'indicator thread'에 해당되는 글 1건

  1. 2012.09.24 [iphone] 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];

- (void)viewDidLoad
    [super viewDidLoad];    

- (void)viewDidUnload
    [self setMyLabel:nil];
    [self setMyButton:nil];
    [super viewDidUnload];


Posted by 예배하는 프로그래머