NSBundle UIImage nil iOS 7 特定

Posted

技术标签:

【中文标题】NSBundle UIImage nil iOS 7 特定【英文标题】:NSBundle UIImage nil iOS 7 specific 【发布时间】:2014-11-19 16:50:56 【问题描述】:

我使用 Xcode 6 Cocoa Touch Framework 目标功能创建了一个框架。 当该框架用于在 ios 8 上运行的另一个应用程序中时,它可以正常工作,加载图像,拾取 nibs-storyboards 等。 当我在 iOS 7 设备上运行相同的应用程序时,代码被拾取,视图控制器正在显示,在界面构建器中为笔尖设置的图像正在显示。但是通过代码设置的图像没有显示出来。

图像存在于应用程序的内容中(当我显示包内容时)。

但它没有被捡起。请看我的代码。

NSString *bundlePath = [NSString stringWithFormat:@"%@/Frameworks/TestFramework.framework", [[NSBundle mainBundle] bundlePath]];

NSBundle *frameworkBundle = [NSBundle bundleWithPath:bundlePath];
[frameworkBundle load];
NSString *imagePath = [NSString stringWithFormat:@"%@/Pic2.JPG", bundlePath];
UIImage *image = [UIImage imageNamed:imagePath];
NSLog(@"FrameworkBundle:%@", frameworkBundle);
NSLog(@"BundlePath:%@", bundlePath);
NSLog(@"ImagePath:%@",imagePath);
NSLog(@"Image:%@",image);
self.imageView3.image = image;

这是输出

2014-11-19 11:48:01.324 TestApp[95937:60b] FrameworkBundle:NSBundle </Users/nbkqkka/Library/Developer/CoreSimulator/Devices/A64CFDA9-EB0E-4B65-B119-A213CD500217/data/Applications/C942AA07-E416-48B3-AE96-C853DB349B64/TestApp.app/Frameworks/TestFramework.framework> (loaded)
    2014-11-19 11:48:01.324 TestApp[95937:60b] BundlePath:/Users/nbkqkka/Library/Developer/CoreSimulator/Devices/A64CFDA9-EB0E-4B65-B119-A213CD500217/data/Applications/C942AA07-E416-48B3-AE96-C853DB349B64/TestApp.app/Frameworks/TestFramework.framework
    2014-11-19 11:48:01.325 TestApp[95937:60b] ImagePath:/Users/nbkqkka/Library/Developer/CoreSimulator/Devices/A64CFDA9-EB0E-4B65-B119-A213CD500217/data/Applications/C942AA07-E416-48B3-AE96-C853DB349B64/TestApp.app/Frameworks/TestFramework.framework/Pic2.JPG
    2014-11-19 11:48:01.474 TestApp[95937:60b] Image:(null)

【问题讨论】:

是的,我已经清理了项目,删除了派生数据等......但它仍然不起作用 【参考方案1】:

imageNamed 的文档说:

文件的名称。如果这是第一次图像 加载后,该方法会在 应用程序的主包。

它没有说明从完整路径加载的任何内容。

你能用吗:

+ (UIImage *)imageWithContentsOfFile:(NSString *)path

改为?

【讨论】:

以上是关于NSBundle UIImage nil iOS 7 特定的主要内容,如果未能解决你的问题,请参考以下文章

[iOS]集成环信SDK然后运行时候crash了-[NSBundle initWithURL:]: nil URL argument'

iOS学习之旅7 NSBundle的pathForResource:ofType: 返回值为nil问题

NSBundle mainBundle 返回 nil

NSBundle.mainBundle() 返回 nil

iOS开发之0行代码加载NSBundle中的@2x与@3x图片

UIStoryboard() 中的 nil 和 NSBundle 有啥区别?