3

我在 iphone 应用程序中使用 UIActivityIndi​​catorView 但它没有停止它的动画没有停止。我正在自我上传方法中将数据上传到服务器

查看是否加载方法

    - (void)viewDidLoad {


    self.navigationController.navigationBarHidden=YES;



   CereniaAppDelegate *appDelegate = (CereniaAppDelegate *)[[UIApplication sharedApplication] delegate];

   activityImageView.hidden=YES;
       activityView.hidden=YES;
   int mytestcount=appDelegate.rowCount;

   NSString*test=[NSString stringWithFormat:@"%d",mytestcount];

  if ([test isEqualToString:@"0"]) {


    NSLog(@" No dta ot upload %d",mytestcount);

  }

 else {

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

       [self uploadData];

    }

  [super viewDidLoad];




[self stopData];    

}

动画停止方法

    -(void)stopData{


[activityView stopAnimating];
activityView.hidden=YES;

activityImageView.hidden=YES;


   }

启动动画方法

    -(void)startActivity:(id)sender
   {

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];



    activityImageView.hidden=NO;
    activityView.hidden=NO;

   [activityView startAnimating];
   [pool release];

  }

上传数据方法

   -(void)uploadData{

CereniaAppDelegate *appDelegate = (CereniaAppDelegate *)[[UIApplication sharedApplication] delegate];

for (int i=0; i<appDelegate.coffeeArray.count; i++) {




    Coffee*coffeeObj=[appDelegate.coffeeArray objectAtIndex:i];



    int mynumber=coffeeObj.participant_Id;
    NSString*question_id=coffeeObj.question_Id;
    NSString*answer_text=coffeeObj.answer_text;
    NSString*answer_option=coffeeObj.answer_option;

    NSString *post =[[NSString alloc] initWithFormat:@"participant_id=%d&question_id=%@&answer_text=%@&answer_option=%@",mynumber,question_id,answer_text,answer_option];




    NSLog(post);
    NSURL *url=[NSURL URLWithString:@"http://celeritas-solutions.com/emrapp/SyncSurveyTest.php"];
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];


    NSError *error;
    NSURLResponse *response;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

    NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
    NSLog(@"%@",data);


     }
    }
4

3 回答 3

0

你没有放[activityView stopAnimating];

于 2012-09-06T09:31:47.347 回答
0

活动.h

//在h文件中声明Activity指标,在Xib中添加Activity指标并连接

IBOutlet UIActivityIndicatorView *activity;

活动.m

 - (void)viewDidLoad
{
    [super viewDidLoad];

    [self startActivity];
}

-(void)startActivity{



    activity.hidden=NO;

    [activity startAnimating];
    [self uploadData];
    [self stopData];

}

-(void)uploadData
{
    NSLog(@"Uploading...");
}

-(void)stopData
{
    [activity stopAnimating];
    activity.hidden=YES;
}
于 2012-09-06T09:32:52.340 回答
0

您需要为活动指示器启用属性 hidesWhenStopped

于 2012-09-06T09:45:33.490 回答