似乎官方文档已过时,并且其解决方案都无法在Titanium iOS模块中使用图像。

根据http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Project,我应该将图像放在资产目录中,并使用相对路径在Objective C代码中获取它。我按照它说的去做,但图片为空。

我找到了实际的应用程序捆绑包,发现图像在modules/moduleid/xxx.png中,但是代码无法加载它。

最佳答案

而是遵循官方指导原则,例如(显然无效):

NSString *path = [NSString stringWithFormat:@"modules/%@/foo.png",[self moduleId]];
NSURL *url = [TiUtils toURL:path proxy:self];
UIImage *image = [TiUtils image:url proxy:self];

做这个:
NSString *imageName = [NSString stringWithFormat:@"modules/%@/foo.png",[self moduleId]];
UIImage *image = [UIImage imageNamed:imageName];

在大多数情况下,此代码将位于自定义视图中,这意味着moduleId将被硬编码。

10-08 13:46