有人建议我使用这行代码从我的资源文件夹/项目包中调用图像。我还看到它在许多不同的网站教程中都以这种方式使用。
NSBundle *mb=[NSBundle mainBundle];
NSString *fp=[mb pathForResource:@"topimage" ofType:@"PNG"];
NSImage *image=[NSImage initWithContentsOfFile:fp];
但是,我收到以下警告:
NSImage 可能无法响应 +initWithContentsOfFile+
NSImage 的文档显示 initWithContentsOfFile 实际上是一种应该有效的方法。我可能在这里缺少什么?