代码之家  ›  专栏  ›  技术社区  ›  Maadiah

进度条不适用于ASIHTTPRequest

  •  0
  • Maadiah  · 技术社区  · 13 年前

    在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 回复  |  直到 13 年前
        1
  •  1
  •   Andrei G.    13 年前
    • 确保您的IBOutlet在IB中正确连接,如果是这种情况,请删除此线路:

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

    …并在IB中配置条形图外观

    • 一定要综合属性 @synthesize progressBar;

    附言

    • IBOutlets最好使用“弱”属性
    • 如果您计划广泛使用ASIHTTPRequest库,那么最好使用其他解决方案。看见 ASIHTTPRequest 以下为: Please note that I am no longer working on this library - you may want to consider using something else for new projects. :)