我试图在UIImageView中仅在应用程序的第一次启动中显示图像。因此,在使用NSUserDefaults来检测成功后,我尝试在MainViewController中加载一个名为firstLaunch.png的图像。
我创建了UIImageView IBOutlet和连接,一切工作正常,但图像不加载。虽然后来在我的代码的其他地方,我可以更新UIImageView成功。这是我尝试加载图像到UIImageView的地方:
[countDownImage setImage:[UIImage imageWithContentsOfFile:@"firstLaunch.png"]];
您可以尝试获取文件的路径。
假设图像在app bundle中,用:
NSString *imgPath = [NSBundle mainBundle] pathForRessource:@"firstLaunch"
ofType:@"png"];
[countDownImage setImage:[UIImage imageWithContentsOfFile:imgPath]];
[countDownImage setImage:[UIImage imageNamed:@"firstLaunch.png"]];