【发布时间】:2011-09-22 13:01:13
【问题描述】:
您好,我的 iPhone 应用程序中有这个奇怪的警告:
-method 'imagePath' not found (return type defaults to 'id'
它在以下行给了我这个警告:
UIImage *image = [UIImage imageNamed:[_occasion imagePath]];
这是我的场合类标题:
#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]
我不知道为什么它抱怨找不到该方法,而它是一个属性并且它确实存在。
【问题讨论】:
-
你在 Occasion.m 中 @synthesize imagePath 了吗?
-
尝试更改其名称(不过我认为这不是问题)。
-
viggo24 yes imagePath是在Occasion.m中合成的
-
EmptyStack 我有很多文件,更改名称需要一些时间。我也不认为这是问题所在。请注意,日期和标题等其他属性不会给出任何错误。另外我在另一个文件中引用 [_occasion imagePath] 并且根本没有警告。真的很奇怪。它可能是编译器中的错误吗?我应该暂时忽略警告吗?
-
实际上在同一行还有另一个警告。它有时只出现并显示:
No '-imagePath' method found。我知道,信息量不大。
标签: iphone class methods properties warnings