“-[__ NSDictionaryI长度]:无法识别的选择器已发送到实例”没有NSDictionary的错误? [英] "-[__NSDictionaryI length]: unrecognized selector sent to instance" error without NSDictionary?

查看:545
本文介绍了“-[__ NSDictionaryI长度]:无法识别的选择器已发送到实例”没有NSDictionary的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,当我按一个按钮打开弹出屏幕时,应该从网站上获取数据并将其存储在字符串中,然后将该字符串放入弹出屏幕上的textview中。当我运行程序并按下按钮进入弹出屏幕时,我收到SIGABRT错误和-[__ NSDictionaryI length]:无法识别的选择器发送到实例。经过研究,我发现当您尝试将NSDictionary引用为length方法时,就会出现错误。我的代码中没有NSDictionary,所以我不知道是什么导致错误。

In my code, when I press a button to open a popup screen, it is supposed to take data from a website and store that in a string, and then put that string into a textview on the popup screen. When I run the program and press the button to get to the popup screen, I get a SIGABRT error and "-[__NSDictionaryI length]: unrecognized selector sent to instance". After researching this, I saw that the error comes when you try to reference NSDictionary to a length method. I don't have an NSDictionary in my code, so I don't know what causes the error.

错误消息


[76416:60b ]-[ NSDictionaryI length]:无法识别的选择器发送到
实例0x8f8ece0 2014-08-13 16:41:59.248 CWSGui [76416:60b] *
正在终止应用由于未捕获的异常
'NSInvalidArgumentException',原因:'-[__ NSDictionaryI长度]:
无法识别的选择器发送到实例0x8f8ece0'
* 第一个抛出调用栈:( 0 CoreFoundation 0x01c0d1e4 __exceptionPreprocess + 180 1 libobjc.A.dylib

0x0198c8e5 objc_exception_throw + 44 2 CoreFoundation

0x01caa243-[NSObject(NSObject)didNotRecognizeSelector:] + 275 3 < $ b CoreFoundation 0x01bfd50b ___ forwarding _
+ 1019
4 CoreFoundation 0x01bfd0ee
_CF_forwarding_prep_0 + 14 5 Foundation 0x015aa4e4-[NSConcreteAttributedString长度] + 42 6 Foundation

0x015a9a6c-[NSConcreteAttributedString initWithString:attributes:] +
182 7 UIKit 0x00d5ae9d-[UITextView
setText:] + 125 8 CWSGui 0x0000805e
-[SystemLog viewDidAppear: ] + 686 9 UIKit 0x0076f099-[UIViewController _setViewAppearState:isAnimating:] + 526
10 UIKit 0x0076f617-[UIViewController
viewDidAppear:] + 146 11 UIKit 0x00771014 __64- [UIViewController
viewDidMoveToWindow :shouldAppearOrDisappear:] _ block_invoke + 44 12
UIKit 0x0076f9aa-[UIViewController
_executeAfterAppearanceBlock] + 63 13 UIKit 0x0066a0d0 ___afterCACommitHandler_block_invoke_2 + 33 14 UIKit
$ b $ ed_p_ly_p _b_to_Array 0x0066 b $ b 0x00669e9a _afterCA CommitHandler + 568 16 CoreFoundation

0x01bd536e
__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
+ 30 17 CoreFoundation 0x01bd52bf __CFRunLoopDoObservers
+ 399 18CoreFoundation 0Run_CF01 01BB23B Run3oop_Loops_Lb = Spec 30B CoreFoundation 0x01CbLb = 399 18BB >
0x01bb27eb CFRunLoopRunInMode + 123 21 GraphicsServices

0x03a3d5ee GSEventRunModal + 192 22 GraphicsServices

0x03a3d42b GSEventRun + 104 23 UIKit

0x0064cf9b CWSUIApplicationMain + 1225

0x00008e2d main + 141 25 libdyld.dylib

0x024be701 start + 1)libc ++ abi.dylib:以未捕获的
类型NSException终止

[76416:60b] -[NSDictionaryI length]: unrecognized selector sent to instance 0x8f8ece0 2014-08-13 16:41:59.248 CWSGui[76416:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI length]: unrecognized selector sent to instance 0x8f8ece0' * First throw call stack: ( 0 CoreFoundation 0x01c0d1e4 __exceptionPreprocess + 180 1 libobjc.A.dylib
0x0198c8e5 objc_exception_throw + 44 2 CoreFoundation
0x01caa243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275 3
CoreFoundation 0x01bfd50b ___forwarding_
+ 1019 4 CoreFoundation 0x01bfd0ee _CF_forwarding_prep_0 + 14 5 Foundation 0x015aa4e4 -[NSConcreteAttributedString length] + 42 6 Foundation
0x015a9a6c -[NSConcreteAttributedString initWithString:attributes:] + 182 7 UIKit 0x00d5ae9d -[UITextView setText:] + 125 8 CWSGui 0x0000805e -[SystemLog viewDidAppear:] + 686 9 UIKit 0x0076f099 -[UIViewController _setViewAppearState:isAnimating:] + 526 10 UIKit 0x0076f617 -[UIViewController viewDidAppear:] + 146 11 UIKit 0x00771014 __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke + 44 12 UIKit 0x0076f9aa -[UIViewController _executeAfterAppearanceBlock] + 63 13 UIKit 0x0066a0d0 ___afterCACommitHandler_block_invoke_2 + 33 14 UIKit
0x0066a055 _applyBlockToCFArrayCopiedToStack + 403 15 UIKit
0x00669e9a _afterCACommitHandler + 568 16 CoreFoundation
0x01bd536e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
+ 30 17 CoreFoundation 0x01bd52bf __CFRunLoopDoObservers + 399 18 CoreFoundation 0x01bb3254 __CFRunLoopRun + 1076 19 CoreFoundation 0x01bb29d3 CFRunLoopRunSpecific + 467 20 CoreFoundation
0x01bb27eb CFRunLoopRunInMode + 123 21 GraphicsServices
0x03a3d5ee GSEventRunModal + 192 22 GraphicsServices
0x03a3d42b GSEventRun + 104 23 UIKit
0x0064cf9b UIApplicationMain + 1225 24 CWSGui
0x00008e2d main + 141 25 libdyld.dylib
0x024be701 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

查看是否出现

- (void)viewDidAppear:(BOOL)animated {

    NSUserDefaults *ipdefaults = [NSUserDefaults standardUserDefaults];

    IPString = [ipdefaults objectForKey:@"IP"];
    NSString *http = @"http://";
    NSString *IPMiddle = [http stringByAppendingString:IPString];
    NSString *IPFinal = [IPMiddle stringByAppendingString:@"/tasks"];
    NSLog(@"Final IP: %@", IPFinal);

    //array stuff from the ip

    array = [[NSMutableArray alloc]init];

    //make a connection
    [self getIPWithIP:IPFinal];

    NSString *str=@"http://example.com";

    NSURL *url=[NSURL URLWithString:str];
    NSData *data=[NSData dataWithContentsOfURL:url];
    NSError *error=nil;
    NSString *string = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error:&error];


    NSLog(@"Your JSON Object: %@", string);
    textField.text = string;
 } 


推荐答案

[NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error:&error];

从不返回字符串。 NSArray或NSDictionary。 (文档仅承诺:数据中JSON数据中的Foundation对象,如果发生错误,则为nil。因此将来可能是另一种类型。)

is never returning a string. Either a NSArray or a NSDictionary. (The documentation only promises: A Foundation object from the JSON data in data, or nil if an error occurs. So it might be another type in future).

您的错误开头


-[NSDictionaryI length]:

-[NSDictionaryI length]:

所以在您的情况下,它是一个字典(NSDictionaryI是NSDictionary的一个具体的不变子类)。

so in your case it is a dictionary (NSDictionaryI is a concrete immutable subclass of NSDictionary).

因为您键入了变量 NSString 不会更改分配给它的对象。

Just because you type the variable NSString it doesn't change the object assigned to it.

这篇关于“-[__ NSDictionaryI长度]:无法识别的选择器已发送到实例”没有NSDictionary的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆