我正在尝试在 iOS 中使用活动指示器但无法使用。我在 Stackoverflow 上关注了一个线程并像这样使用它。这就是我写的:
-(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。但我看不到活动指示器。我究竟做错了什么?如果您需要更多信息,请询问。谢谢..