Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 从数据库检索NSData时,将无法识别的选择器错误发送到uu NSCFString_Objective C_Cocoa Touch_Ios5_Uiimage_Nsdate - Fatal编程技术网

Objective c 从数据库检索NSData时,将无法识别的选择器错误发送到uu NSCFString

Objective c 从数据库检索NSData时,将无法识别的选择器错误发送到uu NSCFString,objective-c,cocoa-touch,ios5,uiimage,nsdate,Objective C,Cocoa Touch,Ios5,Uiimage,Nsdate,我无法将NSData转换为UIImage 我从设备摄像头捕获一个图像,并将该图像转换为NSData,以使用BLOB数据类型将其存储在SQLite中 图像数据已成功存储在数据库中,但当我检索图像数据时,应用程序崩溃 我使用以下代码: NSData *tempData = [[NSData alloc] init]; tempData = [[arr_img objectAtIndex:indexPath.row] valueForKey:@"Image"]; UIImage *img = [[U

我无法将
NSData
转换为
UIImage

我从设备摄像头捕获一个图像,并将该图像转换为
NSData
,以使用BLOB数据类型将其存储在SQLite中

图像数据已成功存储在数据库中,但当我检索图像数据时,应用程序崩溃

我使用以下代码:

NSData *tempData = [[NSData alloc] init];
tempData = [[arr_img objectAtIndex:indexPath.row] valueForKey:@"Image"];

UIImage *img = [[UIImage alloc] initWithData:tempData];
并获取以下错误:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[\uu NSCFString bytes]:无法识别的选择器已发送到实例0x5f8c000”


我做错了什么?

你可以这样做

NSData *data = yourData;
UIImage *image = [UIImage imageWithData:data];


如果它确实起作用,则意味着ur NSData的值可能存在一些问题

将图像插入SQLite:

sqlite3_bind_blob(compiledStatement,i, [image_data bytes], [image_data length], SQLITE_TRANSIENT);
并从SQLite获取图像:

NSData *dataForCachedImage = [[NSData alloc] initWithBytes:sqlite3_column_blob(compiledStatement, i) length: sqlite3_column_bytes(compiledStatement, i)];           
UIImage *img = [UIImage imageWithData:dataForCachedImage];

这里的“i”是您的数据库列号

您如何在sqlite中存储NSData?为什么
alloc/init
立即重写
tempData
?您的数据中一定有错误@赫克托:我用这行app.picdata=[AvCaptureSillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]存储数据;好的,但是“compiledStatement”的意思是dbpath,还有别的吗!!sqlite3_stmt*编译语句@keyurbhalodiya plz指的是:
NSData *dataForCachedImage = [[NSData alloc] initWithBytes:sqlite3_column_blob(compiledStatement, i) length: sqlite3_column_bytes(compiledStatement, i)];           
UIImage *img = [UIImage imageWithData:dataForCachedImage];