开发者

Why UIProgressView fills its progress bar first when i write myProgressView.hidden = FALSE?

开发者 https://www.devze.com 2023-04-12 15:28 出处:网络
I am sending a string to a web server from my iphone application. I am using UIProgressView to show the progress of request. Following is my code:

I am sending a string to a web server from my iphone application. I am using UIProgressView to show the progress of request. Following is my code:

  -(IBAction)sendToServer:(id)sender{

NSString *url = [RequestUtil getWebURL];
NSString *jsonString = [JSONUtil jsonRunData: self.runDetails];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
ASIFormDataRequest *req开发者_如何转开发uest = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:url]]; 
[request setTimeOutSeconds:60];
[request setPostValue:jsonString forKey:@"jsondata"];
[request setUploadProgressDelegate:myProgressIndicator];
[request setDelegate:self]; 
[request startAsynchronous];
progressTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(increaseAmount) userInfo:nil repeats:YES];
 }

 - (void)requestFailed:(ASIHTTPRequest *)request{
   self.myProgressIndicator.hidden = TRUE;
 //    alert
 }

 - (void)requestFinished:(ASIHTTPRequest *)request { 
   myProgressIndicator.progress = 1.0;
    // alert
 }

 -(void) increaseAmount{
progressNumber = progressNumber+0.2;
if(progressNumber <= 0.9){
    myProgressIndicator.progress = progressNumber;
}else {
    [progressTimer invalidate];
    progressNumber = 0.0;
}
 }

when i press send to server button, sendToServer is called. and it shows UIProgressView. Problem is that when progress view is showed it fills its progress bar quickly and then start again and acts on timer. Why progress view fills progress bar before it starts acting on behalf of timer?


I know this is an old question and you've probably moved on, but I suspect that the source of the problem is the fact that the progress property is animated by default. Call [myProgressIndicator setProgress:0.0 animated:NO] prior to showing the progress view.

0

精彩评论

暂无评论...
验证码 换一张
取 消