开发者

Cannot find protocol declaration NSObject

开发者 https://www.devze.com 2023-04-07 13:29 出处:网络
I am about to try and pass a value that the suer selectes in a subview back to the mainview of my application. I have been doing abit of reading about how to do it, and am currently following a fairly

I am about to try and pass a value that the suer selectes in a subview back to the mainview of my application. I have been doing abit of reading about how to do it, and am currently following a fairly informative tutorial here

I am starting from step 18 and implementing this into my code as it seems fairly straight forward... however I have this error in my secondview.h file where I am declaring my protocol as follows.

#import <UIKit/UIKit.h>

@protocol PassSearchData <nsobject> //this is where I get the "Cannot find protocol declaraton for 'nsobject' error
@r开发者_运维问答equired
- (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..


As Malcolm Box mentioned in the comment, NSObject (and most source code, for that matter) is case-sensitive. Also, I'm not sure what the last line with </PassSearchData></nsobject></uikit/ uikit.h> is supposed to be. I'd suggest something like the following:

#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

That code should probably compile, but that doesn't necessarily mean it's problem-free. Traditionally, delegates are not retained, because of the problem of retain cycles. So I changed the declaration of the delegate property from retain to assign.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号