【问题标题】:-[__NSDictionaryI name]: unrecognized selector in objective c-[__NSDictionaryI name]:目标 c 中无法识别的选择器
【发布时间】:2014-10-20 13:39:52
【问题描述】:

-[__NSDictionaryI name]:无法识别的选择器发送到实例 0x7fae38527a80 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSDictionaryI name]:无法识别的选择器发送到实例 0x7fae38527a80” ![在此处输入图片说明][1]

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);

【问题讨论】:

  • 请添加正确的问题描述。仅发布错误消息不会为您提供任何帮助。
  • 是什么让你认为jsonObjectsNSDictionary

标签: objective-c xcode


【解决方案1】:

你假设你的电话在这里:

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

没有失败。不要将 nil 传递给错误参数。传递一个真正的 NSError 并检查值。

【讨论】:

  • 我可以假设我在这里调用 [recipes addObject:dict]; NSLog(@"recipes = %@",recipes); dropbox.com/s/ow5fjwkbz84lnb8/Code%20iOS.zip?dl=0请..
  • 不,在您知道 recipies 是一个 NSDictionary 之前,您不能做出这样的假设。一种简单的确定方法是检查错误参数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多