大家好我是Xcode的新手我正在尝试将图像从UITableView插入到ios 5中的数据库(sqlite3)我尝试了下面的代码
-(void)addItemCUR
{
if(addStmt == nil) {
const char *sql = "insert into Table(C_Name, C_Image) Values(?,?)";
if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}
sqlite3_bind_text(addStmt, 1, [C_Name UTF8String], -1, SQLITE_TRANSIENT);
NSData *ImageData = [[NSData alloc] initWithData:UIImagePNGRepresentation(self.C_Image)];
int returnValue = -1;
if(self.C_Image != nil)
returnValue = sqlite3_bind_blob(addStmt, 3, [ImageData bytes], [ImageData length], NULL);
else
returnValue = sqlite3_bind_blob(addStmt, 4, nil, -1, NULL);
if(SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
else
//SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid
rowid = sqlite3_last_insert_rowid(database);
//Reset the add statement.
sqlite3_reset(addStmt);
}
我收到类似的错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString CGImage]: unrecognized selector sent to instance 0xb7c0'
*** First throw call stack:
(0x158f052 0x1720d0a 0x1590ced 0x14f5f00 0x14f5ce2 0xf8b6c 0x5c65 0x3182 0x7030 0x16d71d 0x16d952 0x9f586d 0x1563966 0x1563407 0x14c67c0 0x14c5db4 0x14c5ccb 0x1478879 0x147893e 0xdda9b 0x2ac8 0x2a25)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
(gdb
请任何人帮助我提前解决这个问题。