2013-02-23 71 views
0

我絕對是一個noob,我真的需要你的幫助。我正在爲一週尋找解決方案,但我真的不知道該怎麼做。 我試圖從網絡服務下載一些圖標(png圖像),並且我已經在其他地方使用了該代碼,但僅針對1張圖像,而不是針對多個圖像。 在這種情況下,我應該下載15個圖像。 在這兩種情況下,使用AFImageRequestOperation或NSURLConnection sendAsynchronousRequest,我達到了所有15個圖像的結束,但之後,它開始一個錯誤,我真的不知道如何解決,因爲它不應該出現在那裏! (*由於未捕獲異常'NSInvalidArgumentException',原因:' - [__ NSCFArray CGPointValue]:無法識別的選擇器發送到實例)終止應用程序。 如果我用synchronousRequest下載了15張圖像,完全沒有問題。 我做錯了什麼?這是我的錯誤還是其他地方? 非常感謝。IOS NSURLConnection和AFImageRequestOperation奇怪的行爲

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:imagePath]]; 
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request imageProcessing``Block:nil                       success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { 
     // Save Image 
     [images_icon addObject:image ]; 
     if ([images_icon count]==[allIcons count]) { 
      [self saveAllImagesToDisk]; 
     } 
     } 
     failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) { 
      NSLog(@"%@", [error localizedDescription]); 
      UIAlertView* allerta=[[UIAlertView alloc] initWithTitle:@"Attention" 
        message:@"Some problems here.." 
        delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
      [allerta show]; 
     }]; 
    [operation start]; 

NSURL *url = [NSURL URLWithString:percorsoImmagine]; 
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; 
    NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 
    [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) 
    {NSLog(@"lungh %d, error=%@ mime=%@",[data length], error, response.MIMEType); 
     if ([data length] > 0 && error == nil && ([response.MIMEType isEqualToString:@"image/png"] || [response.MIMEType isEqualToString:@"image/jpeg"])){ 
      [images_icon addObject:data ]; 
      if ([images_icon count]==[allIcons count]) { 
       [self saveAllImagesToDisk]; 
      } 
     } 
    }]; 
+0

向我們展示它在哪裏崩潰。在每種情況下設置一個斷點,然後進入調試器直至崩潰。 – Ric 2013-02-23 18:37:50

回答

0

當您使用AFImageRequestOperation要添加UIImage s到images_icon但是當你用NSURLConnection要添加NSData s到images_icon。我們需要看到[self saveAllImagesToDisk]進一步調查。

+0

謝謝Ric。我在那裏嘗試了不同的東西;該方法爲空,我將saveAllImagesToDisk中的每一行都排除在外,但在輸入它之前,我遇到了同樣的錯誤。有時它會停留在最後一張圖片上,其他圖片隨機放置。我正在考慮一些網速問題:( – Mchurch 2013-02-23 18:30:57

+0

沒有任何問題,因爲某些原因,某些圖像導致了這個問題,我在服務器上刪除它們,我重新創建了錯誤的,現在一切都是因爲它應該工作..謝謝! – Mchurch 2013-02-23 22:07:51