Thursday, January 2, 2014

How to eliminate the following warning

posts by fanhoucheng on 2010-12-15 11:49:09 Edit
Why do I have such a program warning:
1.
/ Users / fanhoucheng / Desktop / RealCode / Classes / RealCodeViewController.m: 86:0 / Users / fanhoucheng / Desktop / RealCode / Classes / RealCodeViewController.m: 86: warning: property 'btnGenerate' requires method '-btnGenerate' to be defined - use @ synthesize, @ dynamic or provide a method implementation

/ Users / fanhoucheng / Desktop / RealCode / Classes / RealCodeViewController.m: 86:0 / Users / fanhoucheng / Desktop / RealCode / Classes / RealCodeViewController.m: 86: warning: property 'btnGenerate' requires the method 'setBtnGenerate:' to be defined - use @ synthesize, @ dynamic or provide a method implementation


Code:
. m file
- (IBAction) clickGenerateButton: (id) sender {
GenerateViewController * generateView = [[GenerateViewController alloc] initWithNibName: @ "generate"
bundle: [NSBundle mainBundle]];
[[Self navigationController] pushViewController: generateView animated: YES];

. h file
@ Interface RealCodeViewController: UIViewController {
IBOutlet UIButton * btnGenerate;
}
@ Property (retain, nonatomic) IBOutlet UIButton * btnGenerate;

- (IBAction) clickGenerateButton: (id) sender;}


---------------
2.
/ Users / fanhoucheng / Desktop / RealCode / Classes / RealCodeViewController.m: 35:0 / Users / fanhoucheng / Desktop / RealCode / Classes / RealCodeViewController.m: 35: warning: 'UIButton' may not respond to '-setTitle: forStates: '

Code:

- (Void) viewDidLoad {
[Super viewDidLoad];
[BtnGenerate setTitle: NSLocalizedString (@ "ButtonGenerate", nil) forStates: UIControlStateNormal];
}
Reply:
Well very clearly warned
. H @ property used in the specified property
The. M no generation method with @ synthesize
Reply:
Upstairs positive solution

Reply:
Add the following code to the. M file
@ Synthesize btnGenerate;
Reply:
Information Warning given very detailed.
The main reason is that you declare a property @ property in the header file, but not in the. M file using the @ synthesize to generate getter and setter methods
Reply:
Of course he is getter and setter methods to achieve

No comments:

Post a Comment