2012-07-18 86 views
0

添加UIProgressView與StoryBoard,並將其設置爲ANIHTTPRequet的進度條 我是否啓動UIProgressView或使用函數setDownloadProgressDelegate:是否正確? TIA! TIA!進度條不工作與ASIHTTPRequest

@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]; 

     } 

回答

1
  • 確保您的IBOutlet中在IB正確連接,如果是這樣的情況下刪除此行:

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

...和配置IB酒吧外觀

  • 確保您合成屬性@synthesize progressBar;

PS。

  • 這是更好,如果你打算大量使用ASIHTTPRequest庫來使用IBOutlets
  • 「弱」屬性,它是使用一些其他的解決辦法是個好主意。見ASIHTTPRequestPlease note that I am no longer working on this library - you may want to consider using something else for new projects. :)
+0

Thanks.The的解決辦法是刪除你的身影out.This似乎初始化兩次行(IB幫助我們INIT一次)。而我試圖移動到另一個庫[UIDownloadBar](。 https://github.com/sakrist/UIDownloadBar)更容易擴展 – Maadiah 2012-07-18 05:50:27