找不到协议声明NSObject

时间:2011-09-26 21:49:47

标签: iphone ios delegates uinavigationcontroller protocols

我即将尝试将suer在子视图中选择的值传递回我的应用程序的主视图。我一直在阅读有关如何做的阅读,目前我正在阅读一篇内容相当丰富的教程here

我从第18步开始并将其实现到我的代码中,因为它似乎相当直接......但是我在我的secondview.h文件中有这个错误,我在这里声明我的协议如下。

#import <UIKit/UIKit.h>

@protocol PassSearchData <nsobject> //this is where I get the "Cannot find protocol declaraton for 'nsobject' error
@required
- (void) setSecondFavoriteColor:(NSString *)secondFavoriteColor;
@end


@interface VehicleResultViewController : UITableViewController <NSXMLParserDelegate> {
//...
//Delegate stuff for passing information back to parent view
    id <PassSearchData> delegate;

}
//..
//Delegate stuff for passing information back to parent view
@property (retain) id delegate;
//..
@end
</PassSearchData></nsobject></uikit/uikit.h> //more errors here also..

1 个答案:

答案 0 :(得分:2)

正如评论中提到的Malcolm Box一样,NSObject(以及大多数源代码)都是区分大小写的。另外,我不确定</PassSearchData></nsobject></uikit/ uikit.h>的最后一行应该是什么。我建议如下:

#import <UIKit/UIKit.h>

@protocol PassSearchData <NSObject>
@required
- (void) setSecondFavoriteColor:(NSString *)secondFavoriteColor;
@end


@interface VehicleResultViewController : UITableViewController <NSXMLParserDelegate> {
//...
//Delegate stuff for passing information back to parent view
    id <PassSearchData> delegate;

}
//..
//Delegate stuff for passing information back to parent view
@property (assign) id <PassSearchData> delegate; // not retain ?
//..
@end

该代码应该可以编译,但这并不一定意味着它没有问题。传统上,由于problem of retain cycles,代理人不会被保留。所以我将delegate属性的声明从retain更改为assign