Я пытаюсь получить изображение асинхронно из URL с AFNetworking 2,0setImageWithURLRequest: placeholderImage: успех: отказ Нет блок не называется
Моя проблема заключается в том, что ни успех, ни неудача называются
Я проверил мой URL в браузере, так что проблема не здесь
UIImageView *imgv = [[UIImageView alloc] init];
[imgv setImageWithURLRequest:myURL
placeholderImage:nil
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
/*some code*/
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
/*some code*/
];
Когда я смотрю глубже setImageWithUrlRequest:placeholderImage:success:failure
__weak __typeof(self)weakSelf = self;
self.af_imageRequestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
self.af_imageRequestOperation.responseSerializer = self.imageResponseSerializer;
[self.af_imageRequestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
if ([[urlRequest URL] isEqual:[strongSelf.af_imageRequestOperation.request URL]]) {
if (success) {
success(urlRequest, operation.response, responseObject);
} else if (responseObject) {
strongSelf.image = responseObject;
}
if (operation == strongSelf.af_imageRequestOperation){
strongSelf.af_imageRequestOperation = nil;
}
}
[[[strongSelf class] sharedImageCache] cacheImage:responseObject forRequest:urlRequest];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
if ([[urlRequest URL] isEqual:[strongSelf.af_imageRequestOperation.request URL]]) {
if (failure) {
failure(urlRequest, operation.response, error);
}
if (operation == strongSelf.af_imageRequestOperation){
strongSelf.af_imageRequestOperation = nil;
}
}
}];
Мой код идет trought [self.af_imageRequestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
с успехом, но я заметил, что __strong __typeof(weakSelf)strongSelf = weakSelf;
являются как nil
Любая идея?
Вам нужно удержать сильную ссылку на 'imgv', чтобы предотвратить ее« освобождение ». Что еще вы делаете с ним, кроме создания экземпляра и вызова 'setImageWithUrlRequest: placeholderImage: success: failure' на нем? –
Когда я использовал afnetworking 1.xx, я делал это '[imgv setDownloadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {}], но я больше не могу этого делать в Afnetworking 2.0, может быть, именно поэтому больше не работает? Так что теперь я больше ничего не делаю – Titozzz
Возможно, вам стоит попробовать добавить 'imgv' в свою иерархию представлений и, таким образом, держать ссылку на нее так, чтобы она не освобождалась ... –