我想在iOS中使用的活動指標,並不能夠。我遵循Stackoverflow上的線程並使用它。這是我寫的:UIActivity指標沒有顯示在iOS應用程序啓動
-(void)viewDidLoad
{
[NSThread detachNewThreadSelector:@selector(threadStartAnimating:) toTarget:self withObject:self];
UITapGestureRecognizer *tGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doThisForTap:)];
tGR.numberOfTapsRequired = 1;
[myRollTypeLabel addGestureRecognizer:tGR];
myRollTypeLabel.userInteractionEnabled = YES;
[self.scrollView addSubview:myRollTypeLabel];
}
- (void) threadStartAnimating:(id)data
{
self.activityIndicatorNew =[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.activityIndicatorNew.color = [UIColor redColor];
[self.activityIndicatorNew startAnimating];
}
- (void)doThisForTap :(UIGestureRecognizer *)gest
{
//lots of computation.
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.activityIndicatorNew stopAnimating];
self.activityIndicatorNew.hidden = YES;
}
但是活動指標根本沒有顯示出來?在「doThisForTap」方法中,我進行計算並移至另一個UIViewController。但我看不到活動指標。我究竟做錯了什麼?如果您需要更多信息,請詢問。謝謝..
我認爲NSThread無法在UIKit中使用(無線程安全)。 – Larme
@Larme。這是我在我的問題中提到的線程http://stackoverflow.com/questions/1850186/iphone-uiactivityindicatorview-not-starting-or-stopping – RookieAppler
嗯,我會做主線程中的動畫,並加載或任何如果它不觸及用戶界面,則希望在另一個線程中同時執行此操作。你可以「重新同步」,有時在最後一步和一步之間做一個小動畫。 – Larme