当'MyObjectViewDelegate'在CLEARLY那里时,找不到协议声明?1

时间:2011-03-24 20:06:42

标签: iphone cocoa-touch ios4 protocols

我有这样的课..

#import "MyObjectAddView.h"
#import "MyAppDelegate.h"

#define myAppDelegate (MyAppDelegate *) [[UIApplication sharedApplication] delegate]

@class MyObjectAddView;

@interface AccountViewController : UIViewController <UIScrollViewDelegate, MyObjectAddViewDelegate, UIImagePickerControllerDelegate> {

    MyObjectAddView *myAddView;
    .....
}

@property (nonatomic, retain) IBOutlet MyObjectAddView *myAddView;

- (id) initWithSettings:(SettingsObject *)settings;

@end

为什么它突然告诉我在我明确导入时找不到'MyObjectAddViewDelegate'的协议声明,并且包括定义协议的@class?这里 MyObjectAddView 设置如何:

#import <UIKit/UIKit.h>
#import "MyAppDelegate.h"

#define myAppDelegate (MyAppDelegate *) [[UIApplication sharedApplication] delegate]

@protocol MyObjectAddViewDelegate;

@interface MyObjectAddView : UIView <UITextFieldDelegate> {

@private
    id <MyObjectAddViewDelegate> delegate;
    ....    
@public
    .....
}

@property(nonatomic, assign) id <MyObjectAddViewDelegate> delegate;
.....

@end

@protocol MyObjectAddViewDelegate <NSObject>
// expense == nil on cancel
- (void)myObjectAddViewDidFinish:(MyObjectAddView *)addView;

@end

一切看起来都很完美,我看不到任何循环进口?!有什么建议可能没有在MyObjectAddView中看到协议定义吗?

感谢。

2 个答案:

答案 0 :(得分:8)

导入该类的标题后,您不需要对类的前向引用。只有当您计划在实现文件中包含标头时才进行前向引用。删除@class MyObjectAddView如果修复了它,请告诉我,如果没有,我可能会为您提供其他解决方案。

答案 1 :(得分:6)

综合讨论:另一种解决方案是检查委托实现和协议声明之间的循环导入。这解决了我的问题。