如何使用计时器设置活动指示器

时间:2011-08-11 14:01:03

标签: iphone objective-c nstimer

如何在我的应用中使用nstimer设置活动指示器。

提前致谢:

1 个答案:

答案 0 :(得分:1)

在头文件中,您需要声明活动指标和活动计时器。

- (void)viewDidLoad {
    [super viewDidLoad];

    activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    activityIndicator.frame = CGRectMake(150,200, 20, 20);

    [self.view addSubview:activityIndicator];

    [activityIndicator startAnimating];

    [activityTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(stopActivity:) userInfo:nil repeats:NO];
    [activityIndicator release];
}
-(void) stopActivity:(NSTimer *) theTimer
{
  [activityIndicator stopAnimating];
  [activityTimer invalidate];
  activityTimer = nil;
}