错误:声明@synthesize方法

时间:2011-08-11 10:40:30

标签: iphone objective-c ios xcode

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

@interface tweetViewController : UIViewController<UIPickerViewDataSource ,UIPickerViewDelegate> {

    NSArray *activities;
    NSArray *feelings;

}

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

#import "tweetViewController.h"
@synthesize activites,feelings;

但它显示了我的错误信息....

3 个答案:

答案 0 :(得分:5)

您需要将其放入实施中。

@synthesize ...行替换为:

@implementation tweetViewController
@synthesize activities, feelings;

@end

您还需要为此声明@property,并以正确的方式关闭@interface

替换以下行:

@interface tweetViewController : UIViewController<UIPickerViewDataSource ,UIPickerViewDelegate> {

    NSArray *activities;
    NSArray *feelings;

}

有了这个:

@interface tweetViewController : UIViewController<UIPickerViewDataSource , UIPickerViewDelegate>

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

@end

答案 1 :(得分:3)

在大括号{}内声明的变量称为ivarsinstance variables。实际上你应该声明这样的属性。

@property (nonatomic, retain) NSArray *activities;

所以你的代码看起来像这样,

@interface tweetViewController : UIViewController<UIPickerViewDataSource ,UIPickerViewDelegate> {

    NSArray *activities; // ivar
    NSArray *feelings;  // ivar
}

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

答案 2 :(得分:1)

@interface tweetViewController : UIViewController<UIPickerViewDataSource ,UIPickerViewDelegate> {

    NSArray *activities;
    NSArray *feelings;

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

@end

你应该首先申报财产。试试这段代码。