错误:声明@synthesize方法

iPh*_*one 2 iphone xcode objective-c ios

我的.h文件中的代码如下所示

@interface tweetViewController : UIViewController<UIPickerViewDataSource ,UIPickerViewDelegate> {

    NSArray *activities;
    NSArray *feelings;

}
Run Code Online (Sandbox Code Playgroud)

在我的.m文件中,我使用了@synthesize属性

#import "tweetViewController.h"
@synthesize activites,feelings;
Run Code Online (Sandbox Code Playgroud)

但它显示我错误消息....

els*_*ooo 5

你需要把它放在一个实现中.

@synthesize ...用这个替换这行:

@implementation tweetViewController
@synthesize activities, feelings;

@end
Run Code Online (Sandbox Code Playgroud)

您还需要为此声明@propertys,并关闭@interface正确的方法:

替换以下行:

@interface tweetViewController : UIViewController<UIPickerViewDataSource ,UIPickerViewDelegate> {

    NSArray *activities;
    NSArray *feelings;

}
Run Code Online (Sandbox Code Playgroud)

有了这个:

@interface tweetViewController : UIViewController<UIPickerViewDataSource , UIPickerViewDelegate>

@property (nonatomic, retain) NSArray *activities;
@property (nonatomic, retain) NSArray *feelings;

@end
Run Code Online (Sandbox Code Playgroud)

  • 而且您还需要在界面中为它们提供属性. (4认同)