xcode 警告“-method”imagePath“未找到(返回类型默认为“id””

发布于 2024-12-06 08:23:36 字数 985 浏览 1 评论 0原文

你好,我的 iphone 应用程序中有这个奇怪的警告:

-method 'imagePath' not found (return type defaults to 'id'

它在以下行给了我这个警告:

UIImage *image =  [UIImage imageNamed:[_occasion imagePath]];

这是我的 Occasion 类标头:

#import <Foundation/Foundation.h>
@interface Occasion : NSObject {

NSString *_title;
NSDate *_date;
NSString *_imagePath;    
}

@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSDate *date;
@property (nonatomic, retain) NSString *imagePath;

+ (id)occasionWithTitle:(NSString *)title
         date:(NSDate *)date
           imagePath:(NSString *)imagePath;

- (id)initWithTitle:(NSString *)title
         date:(NSDate *)date
           imagePath:(NSString *)imagePath;
@end

奇怪的是我仅在 Occasion 的 (imagePath 属性,而其他2 个属性工作正常:

[_occasion date]

[_occasion title]

不知道为什么它抱怨找不到该方法,而它是一个属性并且确实存在。

Hi I have this weird warning in my iphone app:

-method 'imagePath' not found (return type defaults to 'id'

It's giving me this warning on the following line:

UIImage *image =  [UIImage imageNamed:[_occasion imagePath]];

Here is my Occasion class header:

#import <Foundation/Foundation.h>
@interface Occasion : NSObject {

NSString *_title;
NSDate *_date;
NSString *_imagePath;    
}

@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSDate *date;
@property (nonatomic, retain) NSString *imagePath;

+ (id)occasionWithTitle:(NSString *)title
         date:(NSDate *)date
           imagePath:(NSString *)imagePath;

- (id)initWithTitle:(NSString *)title
         date:(NSDate *)date
           imagePath:(NSString *)imagePath;
@end

The weird thing is I'm getting this warning only on the (imagePath property of Occasion, while the other 2 properties are working fine namely:

[_occasion date]

and

[_occasion title]

I dunno why is it complaining the method is not found while it is a property and it does exist.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

So尛奶瓶 2024-12-13 08:23:36

我终于找到了解决方案。我在 MyFile.m 中导入了 Occasion.h 文件,因为我仅在 MyFile.h 中使用了前向声明 @class Occasion.h。
虽然还是很奇怪
因为 AnotherFile.h 中只有 @class Occasion.h 就足够了,无需在 AnotherFile.m 中导入

I finally found the solution. I imported the Occasion.h file in MyFile.m since I was using the forward declearation @class Occasion.h only in MyFile.h.
It's still weird though
cuz in AnotherFile.h only @class Occasion.h was enough without the import in the AnotherFile.m

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文