将图像添加到ios中从sqlite返回的uiimageView图像名称
我正在尝试向UIImageView添加图像:将图像添加到ios中从sqlite返回的uiimageView图像名称,ios,objective-c,sqlite,uiimageview,Ios,Objective C,Sqlite,Uiimageview,我正在尝试向UIImageView添加图像: UIView *viewTemp=[[UIView alloc] initWithFrame:CGRectMake(2, 2, 140, 140)]; UIImageView *tempImg1=[[UIImageView alloc] initWithFrame:CGRectMake(xPos, yPos, 70, 70)]; NSString *imageNameTemp=[[imageNamesArry objectAtIndex:0 ] o
UIView *viewTemp=[[UIView alloc] initWithFrame:CGRectMake(2, 2, 140, 140)];
UIImageView *tempImg1=[[UIImageView alloc] initWithFrame:CGRectMake(xPos, yPos, 70, 70)];
NSString *imageNameTemp=[[imageNamesArry objectAtIndex:0 ] objectAtIndex:3 ];
tempImg1.image=[UIImage imageNamed:imageNameTemp];
[viewTemp addSubview:tempImg1];
当我执行代码时,图像不显示。
这里imageNamesArry是一个数组数组,它包含从sqlite查询返回的索引3处的图像名称,如下所示:
while (sqlite3_step(compiledstatement)==SQLITE_ROW)
{
for (int i=0; i<5; i++)
{
char *temp =(char *) sqlite3_column_text(compiledstatement, i);
if (temp==NULL)
resultStr=@"";
else
resultStr=[NSString stringWithUTF8String:temp];
[tempFCardssAry addObject:resultStr];
}
[imageNamesArry addObject:tempFCardssAry];
fcSetsDataAry=[[NSMutableArray alloc] init];
}
然后正确添加图像。在循环结束时重新分配ImageNameMarry,似乎没有在其中放置任何对象。也许您应该更改NSString*imageNameTemp=[[FCSETSDatary objectAtIndex:i]objectAtIndex:3];像这样。谢谢你的快速回复。我现在改变了问题。在添加图像之前,我在数组中有所有对象。可能是因为数组返回的字符串格式正确。如果a手动使用了另一个名称,那么它添加了正确的imageNameTemp的值是多少?尝试NSLog。当temp==NULL时也尝试NSLogging,无论每个字符串是否返回nil。然后,如果SQL statement.NSLog中存在ImageNameMarry,我们可以查找错误。是否正确显示存储在sqlite中的图像名称?要显示的图像位于主捆绑包或文档目录中?
NSString *imageNameTemp=@"imageName.jpg";