UIImage imageNamed returns nil 除了第一张图片

UIImage imageNamed returns nil except for the first image

我正在使用 [UIImage imageNamed:@"filename"] 方法从我的应用程序 image.xcassets 加载图像,只有第一张图像正确加载,然后是其余图像returns 零并使应用程序崩溃。下面是我的代码:

[self.imagePicker addImage:[UIImage imageNamed:@"image0-150x277"]];
[self.imagePicker addImage:[UIImage imageNamed:@"image1-150x277"]];
[self.imagePicker addImage:[UIImage imageNamed:@"image2-150x277"]];
[self.imagePicker addImage:[UIImage imageNamed:@"image3-150x277"]];
[self.imagePicker addImage:[UIImage imageNamed:@"image4-150x277"]];
[self.imagePicker addImage:[UIImage imageNamed:@"image5-150x277"]];
[self.imagePicker addImage:[UIImage imageNamed:@"image6-150x277"]];
[self.imagePicker addImage:[UIImage imageNamed:@"image7-150x277"]];
[self.imagePicker addImage:[UIImage imageNamed:@"image8-150x277"]];

这是我的 addImage 方法:

- (void)addImage:(UIImage *)image 
{
    [_images addObject:image];
    [_thumbs addObject:image];
}

我已经检查了这个 question 并尝试了其中的所有内容,包括文件名检查并确保图像是 Retina 2x,但没有任何效果。 关于可能出错的任何想法?

这是崩溃日志:

2016-10-14 15:28:10.280 Munasabah[38773:1038198] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack: ( 0 CoreFoundation 0x000000010d65134b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010d0b221e objc_exception_throw + 48 2 CoreFoundation 0x000000010d58238f -[__NSArrayM insertObject:atIndex:] + 1375 3 Munasabah 0x0000000108dcb669 -[CustomImagePicker addImage:] + 73 4 Munasabah 0x0000000108dc8012 -[FlipsideViewController viewDidLoad] + 994 5 UIKit 0x000000010b4cd06d -[UIViewController loadViewIfRequired] + 1258 6 UIKit 0x000000010b4cd4a0 -[UIViewController view] + 27 7 UIKit 0x000000010bd918d0 -[_UIFullscreenPresentationController _setPresentedViewController:] + 87 8 UIKit 0x000000010b4a7d26 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 141 9 UIKit 0x000000010b4e030b -[UIViewController _presentViewController:withAnimationController:completion:] + 3956 10 UIKit 0x000000010b4e36df -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 530 11 UIKit 0x000000010b4e31c5 -[UIViewController presentViewController:animated:completion:] + 179 12 Munasabah 0x0000000108dc7632 -[MainViewController showInfo:] + 354 13 UIKit 0x000000010b32db88 -[UIApplication sendAction:to:from:forEvent:] + 83 14 UIKit 0x000000010b4b32b2 -[UIControl sendAction:to:forEvent:] + 67 15 UIKit 0x000000010b4b35cb -[UIControl _sendActionsForEvents:withEvent:] + 444 16 UIKit 0x000000010b4b24c7 -[UIControl touchesEnded:withEvent:] + 668 17 UIKit 0x000000010b39b0d5 -[UIWindow _sendTouchesForEvent:] + 2747 18 UIKit 0x000000010b39c7c3 -[UIWindow sendEvent:] + 4011 19 UIKit 0x000000010b349a33 -[UIApplication sendEvent:] + 371 20 UIKit 0x000000010bb3bb6d __dispatchPreprocessedEventFromEventQueue + 3248 21 UIKit 0x000000010bb34817 __handleEventQueue + 4879 22 CoreFoundation 0x000000010d5f6311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 23 CoreFoundation 0x000000010d5db59c __CFRunLoopDoSources0 + 556 24 CoreFoundation 0x000000010d5daa86 __CFRunLoopRun + 918 25 CoreFoundation 0x000000010d5da494 CFRunLoopRunSpecific + 420 26 GraphicsServices 0x000000010f712a6f GSEventRunModal + 161 27 UIKit 0x000000010b32bf34 UIApplicationMain + 159 28 Munasabah 0x0000000108dc430e main + 62 29 libdyld.dylib 0x000000010df2c68d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

以及目标会员的屏幕截图:

屏幕截图中的图像名称似乎与您在代码中使用的名称不同!在代码中它最后有一个“277”,而在图像名称中它是一个“227”