2011-08-11 28 views
2

我有一些代碼在我的.h文件如下錯誤:在聲明@合成方法

@interface tweetViewController : UIViewController<UIPickerViewDataSource ,UIPickerViewDelegate> { 

    NSArray *activities; 
    NSArray *feelings; 

} 

,並在我的.m文件我用@synthesize物業

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

,但它爲我的錯誤消息....

回答

5

你需要把它放在一個實現中。

這種替換@synthesize ...行:

@implementation tweetViewController 
@synthesize activities, feelings; 

@end 

您還需要爲這個聲明@property S,並關閉@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 
+4

而且您還需要在界面中爲它們設置屬性。 – 2011-08-11 10:45:07

+1

這是正確的,我將它添加到我的答案=)。 – elslooo

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 
1
@interface tweetViewController : UIViewController<UIPickerViewDataSource ,UIPickerViewDelegate> { 

    NSArray *activities; 
    NSArray *feelings; 

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

@end 

應先申報財產。試試這個代碼。