进度条不适用于ASIHTTPRequest

时间:2012-07-18 02:25:02

标签: ios asihttprequest uiprogressview

使用StoryBoard添加UIProgressView,并将其设置为ANIHTTPRequet的进度条 我是否正确启动UIProgressView或使用函数setDownloadProgressDelegate: 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];

      }

1 个答案:

答案 0 :(得分:1)

  • 确保您的IBOutlet在IB中正确连接,如果是这样的话,请删除此行:

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

...并在IB中配置栏外观

  • 确保您合成了属性@synthesize progressBar;

PS。

  • 最好对IBOutlets使用'weak'属性
  • 如果您计划广泛使用ASIHTTPRequest库,最好使用其他解决方案。请参阅ASIHTTPRequestPlease note that I am no longer working on this library - you may want to consider using something else for new projects. :)