- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的代码,
for (int i=0; i<=[selfLinksArray count]; i++) {
NSString *temp = selfLinksArray[i];
NSURL *tempURL = [NSURL URLWithString:temp ];
NSLog(@"NSURL:%@",tempURL);
NSData *tempData = [NSData dataWithContentsOfURL:tempURL];
NSError *error = nil;
NSDictionary *tempDict = [NSJSONSerialization JSONObjectWithData:tempData options:0 error:&error];
NSDictionary *volumeInfoDict = [tempDict objectForKey:@"volumeInfo"];
titleArray[i]=[volumeInfoDict objectForKey:@"title"];
}
Xcode 显示这个错误
[__NSArrayI length]: unrecognized selector sent to instance 0x7fdf334f0bc0
2016-01-19 16:12:34.937 BookFindr[7775:449799] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x7fdf334f0bc0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010f34be65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010edc4deb objc_exception_throw + 48
2 CoreFoundation 0x000000010f35448d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010f2a190a ___forwarding___ + 970
4 CoreFoundation 0x000000010f2a14b8 _CF_forwarding_prep_0 + 120
5 CoreFoundation 0x000000010f32e261 _CFURLCreateWithURLString + 81
6 Foundation 0x000000010e97a465 -[NSURL(NSURL) initWithString:relativeToURL:] + 349
7 Foundation 0x000000010e97a2e2 +[NSURL(NSURL) URLWithString:relativeToURL:] + 59
8 BookFindr 0x000000010e8bf9ab -[tabResTableViewController viewDidLoad] + 219
9 UIKit 0x000000010f88ef98 -[UIViewController loadViewIfRequired] + 1198
10 UIKit 0x000000010f894f4f -[UIViewController __viewWillAppear:] + 120
11 UIKit 0x000000010f8c4e44 -[UINavigationController _startCustomTransition:] + 1203
12 UIKit 0x000000010f8d523f -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
13 UIKit 0x000000010f8d63af -[UINavigationController __viewWillLayoutSubviews] + 57
14 UIKit 0x000000010fa7cff7 -[UILayoutContainerView layoutSubviews] + 248
15 UIKit 0x000000010f7af4a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
16 QuartzCore 0x000000011327b59a -[CALayer layoutSublayers] + 146
17 QuartzCore 0x000000011326fe70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
18 QuartzCore 0x000000011326fcee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
19 QuartzCore 0x0000000113264475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
20 QuartzCore 0x0000000113291c0a _ZN2CA11Transaction6commitEv + 486
21 UIKit 0x000000010f6f2f7c _UIApplicationHandleEventQueue + 7329
22 CoreFoundation 0x000000010f277a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
23 CoreFoundation 0x000000010f26d95c __CFRunLoopDoSources0 + 556
24 CoreFoundation 0x000000010f26ce13 __CFRunLoopRun + 867
25 CoreFoundation 0x000000010f26c828 CFRunLoopRunSpecific + 488
26 GraphicsServices 0x0000000112b08ad2 GSEventRunModal + 161
27 UIKit 0x000000010f6f8610 UIApplicationMain + 171
28 BookFindr 0x000000010e8c101f main + 111
29 libdyld.dylib 0x0000000111a8792d start + 1
30 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
我已经从另一个 viewController 导入了 selfLinkArray。我想获取 VolumeInfo 字典中存在的各种标题。该字典存在于 selfLinksArray 中的每个单独链接中。请帮我解决这个错误。提前致谢。
最佳答案
让我们分析您的错误和回溯:
-[__NSArrayI length]: unrecognized selector sent to instance 0x7fdf334f0bc0'
问题写在这里:length
方法在 NSArray
对象上被调用。等等,这个示例中甚至没有写这个方法!别着急,我们来分析一下。
6 Foundation 0x000000010e97a465 -[NSURL(NSURL) initWithString:relativeToURL:] + 349
7 Foundation 0x000000010e97a2e2 +[NSURL(NSURL) URLWithString:relativeToURL:]
崩溃日志表明当您尝试初始化 NSURL
对象时发生崩溃。这个 init 方法的唯一参数是一个 NSString
对象。但是我们确定 temp
真的是一个 NSString
对象吗?
这个变量在没有检查它是否真的是一个 NSString
对象的情况下被转换。它可以是一个东西,例如...... NSArray
接收对 length
方法的调用。此外,此方法适用于 NSString
对象,因此 unrecognizer selector
错误看起来完全相关。
我们在哪里调用此 NSString
对象的 length
?我的猜测是,根据回溯,URLWithString:
调用此方法来检查 NSString
长度,以便正确初始化 NSURL
对象。
关于ios - 在 "for"循环中使用 NSURL URLWithString 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34887078/
我对 Facebook 页面的操作有疑问。 currentVriend 是一个 NSObject 类。 我收到错误:方法调用的参数太多,预期 1 有 2 -(void)goFB { NSURL
假设,我有一个地址栏,它是一个名为 textField 的 UITextField 和一个名为 webView 的 UIWebView。大多数情况下,以下代码有效: [webView loadURL:
我正在尝试从这样的字符串构建NSURL: NSString *urlString = self.providerData[@"LogoUrl"]; NSURL *url = [NSURL URLWit
我正在使用 QLPreviewController 查看 word、excel、pdf 等。问题是文件在服务器中,所以我需要从某个 URL 下载它。 我正在使用这段代码: NSURL *dLurl =
我正在启动一个 iOS 项目,其中包括从网页中解析一些数据。我正打算使用 我开始使用“http://www.facebook.com”。作为我的测试用例,以及 XPath(通过 Hpple 使用 Li
我尝试将 NSString 转换为 NSURL,但是我收到了截断的 url。 NSURL *url = [NSURL fileURLWithPath:music.url]; 如果我制作 NSLog m
我有这个代码: NSString *logsPath = [dataDirectoryPath stringByAppendingPathComponent:@"Logs"]; 哪个返回: /var/
这可能很容易,但我似乎不明白为什么 URLWithString: 在这里返回 nil。 //localisationName is a arbitrary string here NSString*
请参阅以下代码: UIImage *image; NSString *str = [[[Data getInstance]arrPic]objectAtIndex:rowIndex]; NSLog(s
由于某种原因获取资源的 URL 时出现问题:此代码位于 viewDidLoad 中,并且在其他应用程序中有效,但由于某种原因在此处不起作用: NSString* audioString = [[NSB
我被困在 NSURL 类 URLWithString 的一个非常明显的方法中 我正在传递一个 string 并在创建 URL 它返回 nil,我的 string 是完美的。当我在浏览器中使用相同的字符
我在 iOS 中构建了一个翻译应用程序。该应用程序使用 Yandex 翻译 api。我遵循了本教程:http://www.raywenderlich.com/5492/working-with-jso
我想从 ios 应用程序上传一个图像(UIImage)到 django 网站。(那里有表单和提交按钮,就像普通网页一样。) 所以我决定为此使用 ASIFormDataRequest。 (我是菜鸟,我做
我使用此代码从 URL 加载 UIImage: NSURL *imageURL = [NSURL URLWithString:@"http://testwebsite.com/image.png"
简而言之,[NSURL URLWithString:] 似乎引发了异常。根据文档“如果字符串格式错误,则返回 nil”。没有提到在任何情况下都会引发异常。除此之外,在将字符串转换为 URL 之前,我对
这是我在 StackOverflow 上发布的第一篇文章,如果我的请求格式不正确,请原谅。 我正在尝试使用以下行将 NSString 类型的变量加载到 NSURL 中: audioPlayer = [
尝试将我的 NSString 传递给 URLWithString 但没有出现 url: //here i get my url from my API and replacing tags NSStr
我正在从 API 接收图像的 url,我想在 Collection View 中显示这些图像。 这是我的代码 NSString *str = [imgArray objectAtIndex:index
我的代码是这样的: NSString *urlStr = [NSString stringWithFormat:@"https://xxx.xxx.xx.xx/Pages/Service/FMServ
这是我的代码, for (int i=0; i<=[selfLinksArray count]; i++) { NSString *temp = selfLinksArray[i];
我是一名优秀的程序员,十分优秀!