点击按钮上的活动指示器

时间:2011-10-10 08:26:19

标签: iphone

我正在创建一个iphone应用程序,在其中一个视图中我试图将活动指示器点击按钮。每当用户点击按钮时,指示器必须启动,并且在此按钮结束时,活动指示器必须停止。我试图实现它。但它不能正常工作。 如果有人有解决方案。请告诉我。

-(void)temp
{
    spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    spinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
    [spinner setCenter:CGPointMake(480/2.0, 128.0/2)]; // (mid of screen) I do this because I'm in landscape mode
    [timetable addSubview:spinner];  
    [spinner startAnimating];       
    [spinner release]; 
}


-(IBAction)datetimeis:(id)sender
{
    [self temp];
    for (int d=0 ; d<=[totaltimearray count]-1; d++) 
    {
        for (int e=0 ; e<=[appendarray count]-1; e++) 
        {
            appenddate = [appendarray objectAtIndex:e];
            datestring = [NSString stringWithFormat:@"%@",appenddate];

        appendtime = [totaltimearray objectAtIndex:d];
        timestring = [NSString stringWithFormat:@"%@",appendtime];

        rslttwostr = [datestring stringByAppendingFormat:@"%@",timestring];
        NSLog(@"timestring is:%@",rslttwostr);
        [dateandtime addObject:rslttwostr];
        NSLog(@"dateandtimeis:%@",dateandtime);
    }
}

totaltimewithdate = dateandtime;
[self savedetails];
[self docmedname];
[self retrivenotificationarray];
//[barButton release];
[self.navigationController popToRootViewControllerAnimated:YES];
}

非常感谢。

1 个答案:

答案 0 :(得分:3)

将此行放在按钮操作开始...

   [NSThread detachNewThreadSelector:@selector(StartActivityIndicator) toTarget:self withObject:nil];   

添加此方法......

-(void)StartActivityIndicator
{
[activityIndicator startAnimating];

}