0

添加带有 StoryBoard 的 UIProgressView,并将其设置为 ANIHTTPRequet 的进度条 我是否正确初始化 UIProgressView 或使用函数 setDownloadProgressDelegate:?蒂亚!

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

      }
4

1 回答 1

1
  • 确保您的 IBOutlet 在 IB 中正确连接,如果是这种情况,请删除此行:

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

...并在 IB 中配置条形外观

  • 确保你综合了财产@synthesize progressBar;

PS。

  • 最好为 IBOutlets 使用“弱”属性
  • 如果您打算广泛使用 ASIHTTPRequest 库,那么使用其他解决方案是个好主意。请参阅ASIHTTPRequestPlease note that I am no longer working on this library - you may want to consider using something else for new projects. :)
于 2012-07-18T04:52:00.180 回答