Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
Ios 仅显示一些png图像,其他图像不显示';无缘无故_Ios_Image - Fatal编程技术网

Ios 仅显示一些png图像,其他图像不显示';无缘无故

Ios 仅显示一些png图像,其他图像不显示';无缘无故,ios,image,Ios,Image,我有一些随机显示给定.png图像及其标题的代码。标题逻辑工作正常。然而,由于某些原因,四幅图像中只有两幅显示出来。为了以防万一,我试着改变顺序,但只有这两张图片,pic_c和pic_d,才会显示出来。我还检查了拼写,以及文件是否在参考资料中,是否存在于文件系统中。以下是显示图像的代码: NSMutableArray *fileNameArray = [[NSMutableArray alloc] init]; [fileNam

我有一些随机显示给定.png图像及其标题的代码。标题逻辑工作正常。然而,由于某些原因,四幅图像中只有两幅显示出来。为了以防万一,我试着改变顺序,但只有这两张图片,pic_c和pic_d,才会显示出来。我还检查了拼写,以及文件是否在参考资料中,是否存在于文件系统中。以下是显示图像的代码:

    NSMutableArray *fileNameArray = [[NSMutableArray alloc] init];                          

    [fileNameArray addObject:[NSString stringWithFormat: @"pic_a"]];     
    [fileNameArray addObject:[NSString stringWithFormat: @"pic_b"]];     
    [fileNameArray addObject:[NSString stringWithFormat: @"pic_c"]];    
    [fileNameArray addObject:[NSString stringWithFormat: @"pic_d"]];     

    NSMutableArray *titleArray = [[NSMutableArray alloc] init];                          

    [titleArray addObject:[NSString stringWithFormat: @"pic a"]];     
    [titleArray addObject:[NSString stringWithFormat: @"pic b"]];     
    [titleArray addObject:[NSString stringWithFormat: @"pic c"]];    
    [titleArray addObject:[NSString stringWithFormat: @"pic d"]];     


    int index = arc4random() % [fileNameArray count];

    NSString *pictureName = [titleArray objectAtIndex:index];  

    art_title.text = pictureName;    

    NSString* imagePath = [ [ NSBundle mainBundle] pathForResource:pictureName ofType:@"png"];


    UIImage *img = [ UIImage imageWithContentsOfFile: imagePath];

    if (img != nil) { // Image was loaded successfully.
        [imageView setImage:img];
        [imageView setUserInteractionEnabled:NO];   
        [img release]; // Release the image now that we have a UIImageView that contains it.
    }

    [super viewDidLoad];

    [fileNameArray release];
    [titleArray release];
}
知道为什么会这样吗


最近的信息:如果我删除titleArray,并且只使用文件名数组,所有图像都会显示出来。但是,我仍然希望能够使用titleArray

您的图像文件实际上被称为什么?在上面的代码中,除了对finleNameArray进行计数之外,实际上没有对它执行任何操作。您可以使用titleArray中的值来获取图像资源。我认为您需要以下代码:

NSString *filename = [fileNameArray objectAtIndex:index];

然后更改您的
imagePath
以使用此文件名,而不是
pictureName

尝试更改文件名,使其不包含u,只是一个猜测。谢谢-另一双眼睛有帮助。