我从数据库中获取数据时的代码: -
while(sqlite3_step(dataRows) == SQLITE_ROW)
{
clsGlobal *temp=[[clsGlobal alloc]init];
//temp.CatId=sqlite3_column_int(dataRows,0);
temp.QId =sqlite3_column_int(dataRows,0);
temp.QName= [NSString stringWithUTF8String:(char *)sqlite3_column_text(dataRows,1)];
temp.ImagePath= [NSString stringWithUTF8String:(char *)sqlite3_column_text(dataRows,2)]; //app crash when imagepath is nil
NSLog(@"%d%@%@",temp.QId,temp.QName,temp.ImagePath);
所以请给我正确的建议和有用的链接。
答案 0 :(得分:3)
在尝试将指针变为NSString
:
char *text = (char *)sqlite3_column_text(dataRows,2);
temp.ImagePath = text ? [NSString stringWithUTF8String:text] : @"no image path in database";