0

add UIProgressView with StoryBoard,and set it as the progress bar of ANIHTTPRequet Do i init the UIProgressView or use function setDownloadProgressDelegate: correctly? TIA!

    @interface xyzViewController : UIViewController {
               ASINetworkQueue *networkQueue;
               BOOL failed;

               ASIHTTPRequest *request;
               NSOperationQueue *queue;
    }
    @property (strong, nonatomic) IBOutlet UIProgressView *progressBar;

//

     - (void)viewDidLoad
     {
             [super viewDidLoad];
             progressBar = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar];
             [progressBar setProgress:0.0 animated:YES];
      }

//

    -(IBAction) downloadStart{

           if (!networkQueue) {
                 networkQueue = [[ASINetworkQueue alloc] init]; 
           }
           failed = NO;

           [networkQueue reset];
           [networkQueue setRequestDidFinishSelector:@selector(imageFetchComplete:)];
           [networkQueue setRequestDidFailSelector:@selector(imageFetchFailed:)];
           [networkQueue setShowAccurateProgress: YES];
           [networkQueue setDelegate:self];


           request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/large-image.jpg"]];
           [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"1.png"]];
           [request setDownloadProgressDelegate:progressBar];
           [request setUserInfo:[NSDictionary dictionaryWithObject:@"request1" forKey:@"name"]];
           [networkQueue addOperation:request];

           [networkQueue go];

      }
Maadiah
  • 431
  • 6
  • 20

1 Answers1

1
  • Make sure your IBOutlet is connected properly in IB, if that's the case remove this line:

progressBar = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar];

...and configure the bar appearance in IB

  • make sure you synthesize the property @synthesize progressBar;

PS.

  • it is better to use 'weak' property for IBOutlets
  • if you plan to use ASIHTTPRequest library extensively, it is a good idea to use some other solution. See ASIHTTPRequest: Please note that I am no longer working on this library - you may want to consider using something else for new projects. :)
Andrei G.
  • 1,710
  • 1
  • 14
  • 23
  • Thanks.The solution is remove the line you figure out.This seems to init it twice(IB help us init once).And i'm trying to move to another library.[UIDownloadBar](https://github.com/sakrist/UIDownloadBar) is much easier to extend – Maadiah Jul 18 '12 at 05:50