UIActivityIndi​​catorView不会停止在iPhone应用程序中

时间:2012-09-06 09:29:15

标签: iphone uiactivityindicatorview

我在iphone应用程序中使用UIActivityIndi​​catorView但它没有停止 它的动画不停止。我在self uploadMethod

中将数据上传到服务器

查看已加载方法

    - (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);


     }
    }

3 个答案:

答案 0 :(得分:0)

您尚未放置[activityView stopAnimating];

答案 1 :(得分:0)

Activity.h

//在h文件中声明活动指示符并在Xib中添加活动指示符并将其连接

IBOutlet UIActivityIndicatorView *activity;

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;
}

答案 2 :(得分:0)

您需要启用属性hidesWhenStopped for activity indicator