關於如何在iOS開發中使用風火輪UIActivityIndicatorView提示載入等待

why_ios發表於2012-07-27

首先,在.h檔案中宣告一個風火輪,以便在後面的程式中進行現實和隱藏的控制。

UIActivityIndicatorView *activityIndicator ;

然後就是在.m檔案中進行載入了。



- (void)PostStockData2:(id)userInfo {    
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];    
      
      
    //這裡寫資料處理  
      
      
    [self performSelectorOnMainThread:@selector(endLoading2) 
                                      withObject:nil waitUntilDone:NO];   
      
    [pool release];    
}  
  
- (void)endLoading2 {   
    //停止動畫  
    [activityIndicator stopAnimating];  
}  
-(IBAction)turnAccount  
{  
    [activityIndicator startAnimating];  
    [NSThread detachNewThreadSelector:@selector(PostStockData2:) 
                                      toTarget:self withObject:nil];   
  
}  
- (void)viewDidLoad  
{  
    [superviewDidLoad];  
    //載入旋轉的風火輪  
    activityIndicator = [[UIActivityIndicatorView alloc]
                         initWithActivityIndicatorStyle:
                         UIActivityIndicatorViewStyleWhiteLarge];  
//    activityIndicator.frame = CGRectMake(0, 0, 30, 30);  
    activityIndicator.center =self.view.center;  
    activityIndicator.hidden =YES;  
    [self.viewaddSubview:activityIndicator];
} 


相關文章