【问题标题】:xcode warning "-method 'imagePath' not found (return type defaults to 'id' "xcode 警告“找不到-method 'imagePath'(返回类型默认为'id'”
【发布时间】: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


【解决方案1】:

我终于找到了解决办法。我在 MyFile.m 中导入了 Occasion.h 文件,因为我只在 MyFile.h 中使用了前向清除 @class Occasion.h。 不过还是很奇怪 因为在 AnotherFile.h 中只有 @class Occasion.h 就足够了,无需在 AnotherFile.m 中导入

【讨论】:

    猜你喜欢
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 2012-09-04
    • 2011-09-28
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多