-1

我从数据库中获取数据时的代码:-

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);

所以请给我正确的建议和有用的链接。

4

1 回答 1

3

在尝试将其变为 之前检查指针NSString

char *text = (char *)sqlite3_column_text(dataRows,2);
temp.ImagePath = text ? [NSString stringWithUTF8String:text] : @"no image path in database";
于 2012-12-01T08:52:53.430 回答