我在 iphone 应用程序中使用 UIActivityIndicatorView 但它没有停止它的动画没有停止。我正在自我上传方法中将数据上传到服务器
查看是否加载方法
- (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);
}
}