【发布时间】:2013-09-11 05:32:30
【问题描述】:
我遇到错误
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:
'-[NSConcreteData initWithContentsOfURL:options:error:]: nil URL argument'`
当我尝试将 viewController 从 ViewControllerA 推送到 ViewControllerB 时,应用程序崩溃
下面是我在ViewControllerB中的代码,
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//this will start the image loading in bg
dispatch_async(concurrentQueue, ^{
NSError *nserror = nil;
NSData *imageData = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:&nserror];
//this will set the image when loading is finished
dispatch_async(dispatch_get_main_queue(), ^{
if (nserror) {
UIImage *image = [UIImage imageNamed:@"prod_img3.png"];
pro_image.image = image;
}
else{
UIImage *image = [UIImage imageWithData:imageData];
pro_image.image = image;
}
[self doneChecking];
});
});
我做错了什么? 感谢您的帮助。
【问题讨论】:
-
错误提示您的 url 参数为 nil。尝试在将 url 参数传递给 dataWithContentsOfURL 之前打印它。
-
当然 url 是 nil...在使用之前记录它
-
我试过但没有解决。收到打印值 null。我可以忽略 URL 的 dataWithContents 吗?
-
@GajendraKChauhan 不,你不能忽视。试试我下面答案中的代码。
标签: iphone ios objective-c