Autosynthesized property 警告解决思路
Autosynthesized property 警告
之前在另外一个viewcontroll实现相同的功能都没有警告,也是相同的声明。但在这个viewcontroller却有这个警告,请问怎修改才能去掉警告。
warning:
Autosynthesized property 'myVar' will use synthesized instance variable '_myVar', not existing instance variable 'myVar'.
我所有在@synthesize 里的变量或者说在@property里面的变量都有这个警告。
我的.h file
我的.m file:
也许有警告的缘故questionInt,questionTitleTrip, NsArray没有显示相关的字体颜色,只是显示黑色的。这个view是一个navigation中得一个view, 需要在编辑的时候把UIview类换成自己本身的类吗,NavigationTripViewController?谢谢
------解决方案--------------------
@property (retain, nonatomic) NSArray *questionTitleTrip;
在头文件中这样写,默认会生成一个_questionTitleTrip变量。
所以,在实现文件中最好这样写。
@synthesize questionTitleTrip = _questionTitleTrip
------解决方案--------------------
接着楼上的说,使用@property定义变量ivar无非三种情况
1)没有合成@synthesized ,则系统会通过Autosynthesized合成一个_ivar
2)如果使用@synthesized ivar;则声称的变量为ivar
3)如果使用@synthesized ivar = _ivar;则声明的变量为_ivar。
之前在另外一个viewcontroll实现相同的功能都没有警告,也是相同的声明。但在这个viewcontroller却有这个警告,请问怎修改才能去掉警告。
warning:
Autosynthesized property 'myVar' will use synthesized instance variable '_myVar', not existing instance variable 'myVar'.
我所有在@synthesize 里的变量或者说在@property里面的变量都有这个警告。
我的.h file
#import <UIKit/UIKit.h>
@interface NavigationTripViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>{
NSArray *questionTitleTrip;
NSArray *questionDescTrip;
NSMutableArray *answerTrip;
NSMutableArray *pickerChoices;
int questionInt;
int totalInt;
IBOutlet UILabel *questionNum;
IBOutlet UILabel *questionTotalNum;
IBOutlet UILabel *recordType;
IBOutlet UITextView *questionDes;
IBOutlet UIView *answerView;
IBOutlet UIButton *preButton;
IBOutlet UIButton *nextButton;
UITextField *text;
UIPickerView *picker;
}
@property (retain, nonatomic) NSArray *questionTitleTrip;
@property (retain, nonatomic) NSArray *questionDescTrip;
@property (retain, nonatomic) NSMutableArray *answerTrip;
@property (retain, nonatomic) NSMutableArray *pickerChoices;
@property (retain, nonatomic) IBOutlet UILabel *questionNum;
@property (retain, nonatomic) IBOutlet UILabel *questionTotalNum;
@property (retain, nonatomic) IBOutlet UILabel *recordType;
@property (retain, nonatomic) IBOutlet UITextView *questionDes;
@property (retain, nonatomic) IBOutlet UIView *answerView;
@property (retain, nonatomic) IBOutlet UIButton *preButton;
@property (retain, nonatomic) IBOutlet UIButton *nextButton;
@property (retain, nonatomic) UITextField *text;
@property (retain, nonatomic) UIPickerView *picker;
-(IBAction)clickPre;
-(IBAction)clickNext;
@end
我的.m file:
#import "NavigationTripViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface NavigationTripViewController ()
@end
@implementation NavigationTripViewController
@synthesize questionTitleTrip,questionDescTrip,answerTripl,pickerChoices,questionNum,questionTotalNum,recordType,questionDes,answerView,preButton,nextButton,text,picker;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
questionInt = 1 ;
questionTitleTrip = [[NSArray alloc] initWithObjects:
@"",
@"Record TYPE 4- Trip Information",
也许有警告的缘故questionInt,questionTitleTrip, NsArray没有显示相关的字体颜色,只是显示黑色的。这个view是一个navigation中得一个view, 需要在编辑的时候把UIview类换成自己本身的类吗,NavigationTripViewController?谢谢
------解决方案--------------------
@property (retain, nonatomic) NSArray *questionTitleTrip;
在头文件中这样写,默认会生成一个_questionTitleTrip变量。
所以,在实现文件中最好这样写。
@synthesize questionTitleTrip = _questionTitleTrip
------解决方案--------------------
接着楼上的说,使用@property定义变量ivar无非三种情况
1)没有合成@synthesized ,则系统会通过Autosynthesized合成一个_ivar
2)如果使用@synthesized ivar;则声称的变量为ivar
3)如果使用@synthesized ivar = _ivar;则声明的变量为_ivar。