Reputation: 29
There is error compiling on line 6 and 7. It says "Expected identifier or (". Can anybody please help me with this one?
#import <UIKit/UIKit.h>
@interface BIDViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *numberField;
@property (weak, nonatomic) IBOutlet UITextField *nameField;
- (IBAction)textFieldDoneEditing:(id)sender;
[self.nameField resignFirstResponder];
[self.numberField resignFirstResponder];
@end
Upvotes: 0
Views: 70
Reputation: 14068
BIDViewController.h:
#import <UIKit/UIKit.h>
@interface BIDViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *numberField;
@property (weak, nonatomic) IBOutlet UITextField *nameField;
- (IBAction)textFieldDoneEditing:(id)sender;
@end
BIDViewController.m:
#include "BIDViewController.h";
@implementation BIDViewController
- (IBAction)textFieldDoneEditing:(id)sender
{
[self.nameField resignFirstResponder];
[self.numberField resignFirstResponder];
}
@end
Upvotes: 1
Reputation: 438232
Your calls to resignFirstResponder
don't belong in the @interface
. They should be called from the relevant method in your @implementation
(e.g. from textFieldShouldReturn
, from a UITapGestureRecognizer
or touchesBegan
elsewhere on the screen, or wherever).
Upvotes: 3
Reputation: 1316
You can't fire methods in your header file. They need to be inside a method in your implementation file. Header(.h) files is for declaring stuff to the compiler etc. and the implementation file(.m) is where the magic should happened.
Do something like this
Your header file..
#import <UIKit/UIKit.h>
@interface BIDViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *numberField;
@property (weak, nonatomic) IBOutlet UITextField *nameField;
- (IBAction)textFieldDoneEditing:(id)sender;
@end
And your implementation file (.m)
#import "BIDViewController.h"
@implementation BIDViewController
- (IBAction)someMethodOrAction:(id)sender {
[self.nameField resignFirstResponder];
[self.numberField resignFirstResponder];
}
@end
Upvotes: 0