Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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
Objective c 为什么我的NSArray没有对象?_Objective C_Uiimage_Nsarray - Fatal编程技术网

Objective c 为什么我的NSArray没有对象?

Objective c 为什么我的NSArray没有对象?,objective-c,uiimage,nsarray,Objective C,Uiimage,Nsarray,我试图将一些UIImage对象添加到数组中,但它不起作用。我尝试将图像添加到NSArray,但由于某种原因,阵列没有保存任何内容 这是我的密码: UIImage *a = [UIImage imageWithContentsOfFile:@"A.jpg"]; UIImage *b = [UIImage imageWithContentsOfFile:@"B.jpg"]; UIImage *c = [UIImage imageWithContentsOfFile:@"C.jpg"]; UIImag

我试图将一些UIImage对象添加到数组中,但它不起作用。我尝试将图像添加到NSArray,但由于某种原因,阵列没有保存任何内容

这是我的密码:

UIImage *a = [UIImage imageWithContentsOfFile:@"A.jpg"];
UIImage *b = [UIImage imageWithContentsOfFile:@"B.jpg"];
UIImage *c = [UIImage imageWithContentsOfFile:@"C.jpg"];
UIImage *d = [UIImage imageWithContentsOfFile:@"D.jpg"];
UIImage *e = [UIImage imageWithContentsOfFile:@"E.jpg"];
UIImage *f = [UIImage imageWithContentsOfFile:@"F.jpg"];

self.imageArray = [NSArray arrayWithObjects:a, b, c, d, e, f, nil];

int firstArrayCount = [self.array count];   
NSLog(@"%d objects in array 1", firstArrayCount);

int secondArrayCount = [self.imageArray count];
NSLog(@"%d objects in array 2", secondArrayCount);

请尝试使用“s
+imageNamed:
加载图像。比如说,

UIImage *a = [UIImage imageNamed:@"A"];
检查所有这些图像是否已添加到项目中,而不仅仅是它们是否显示在XCode窗格中。否则,仅假设此代码不在同一范围内,请检查
NSArray
属性是否为retain而不是assign

UIImage *a = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"A" ofType:@".jpg"]];
UIImage *b = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"B" ofType:@".jpg"]];
UIImage *c = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"C" ofType:@".jpg"]];
UIImage *d = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"D" ofType:@".jpg"]];
UIImage *e = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"E" ofType:@".jpg"]];
UIImage *f = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"F" ofType:@".jpg"]];

NSArray *imageArray = [NSArray arrayWithObjects:a, b, c, d, e, f, nil];

int secondArrayCount = [imageArray count];
NSLog(@"%d objects in array 2", secondArrayCount);

UIImage *a = [UIImage imageNamed:@"A.jpg"];
UIImage *b = [UIImage imageNamed:@"B.jpg"];
UIImage *c = [UIImage imageNamed:@"C.jpg"];
UIImage *d = [UIImage imageNamed:@"D.jpg"];
UIImage *e = [UIImage imageNamed:@"E.jpg"];
UIImage *f = [UIImage imageNamed:@"F.jpg"];

NSArray *imageArray = [NSArray arrayWithObjects:a, b, c, d, e, f, nil];

int secondArrayCount = [imageArray count];
NSLog(@"%d objects in array 2", secondArrayCount);

是否确实没有图像是
nil
?[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@“A”of type:@.jpg]];