2014-10-20 35 views
-7

- [__ NSDictionaryI名]:「 - [__ NSDictionaryI名]:發送到實例0x7fae38527a80 終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因無法識別選擇無法識別的選擇發送到!例如0x7fae38527a80' [在這裏輸入的形象描述] [1]- [__ NSDictionaryI名]:在目標C無法識別選擇

imageid = @"ImageID"; 
     name = @"Name"; 
     path = @"Path"; 
     // And add a few recipes to it 
     recipes = [NSMutableArray arrayWithCapacity:10]; 
     Recipe* recipe = [[Recipe alloc] init]; 


    //  recipe.name = @"Image 1"; 
    //  recipe,path = @"http://absolutesoft.net/test/ios/col/img/img1.png"; 
    //  recipe.image = [UIImage imageNamed:@"Image 2"]; 
    //  [recipes addObject:recipe]; 



      NSData *jsonData = [NSData dataWithContentsOfURL: 
           [NSURL URLWithString:@"http://absolutesoft.net/test/ios/col/getImages.php"]]; 

      id jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil]; 

      // values in foreach loop 
      for (NSDictionary *dataDict in jsonObjects) { 


       recipe.image = [dataDict objectForKey:@"ImageID"];; 
       recipe.name = [dataDict objectForKey:@"Name"]; 
       recipe.Path = [dataDict objectForKey:@"Path"]; 
       NSLog(@"recipe.image %@",recipe.image); 
       NSLog(@"recipe.name %@",recipe.image); 
       NSLog(@"recipe.Path %@",recipe.Path); 

       dict = [NSDictionary dictionaryWithObjectsAndKeys: 
         recipe.image, imageid, 
         recipe.name, name, 
         recipe.Path, path, 
         nil]; 
       [recipes addObject:dict]; 
      } 
      //NSLog(@"Dict = %@",dict); 
     NSLog(@"recipes = %@",recipes); 
+2

請添加正確的問題描述。只是發佈錯誤消息不會給你任何幫助。 – Fred 2014-10-20 13:44:14

+1

是什麼讓你覺得'jsonObjects'是一個'NSDictionary'? – zaph 2014-10-20 13:49:59

回答

1

你讓你的來電來訪的假設:

 id jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil]; 

沒有失敗。不要將nil傳遞給錯誤參數。傳遞一個真正的NSError並檢查值。

+0

我可以假設我在這裏打電話 [recipes addObject:dict]; NSLog(@「recipes =%@」,食譜); https://www.dropbox.com/s/ow5fjwkbz84lnb8/Code%20iOS.zip?dl=0 請.. – Mon 2014-10-20 16:52:11

+0

不,你不能做這個假設,直到你知道recipies是一個NSDictionary。一個簡單的方法是確認錯誤參數。 – 2014-10-20 17:33:00

相關問題