第6行和第7行有错误编译。它说“预期标识符或(”。有人可以帮我这个吗?
#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
答案 0 :(得分:3)
您对resignFirstResponder
的来电不属于@interface
。应该通过@implementation
中的相关方法(例如来自textFieldShouldReturn
,来自屏幕上其他地方的UITapGestureRecognizer
或touchesBegan
或任何地方)来调用它们。
答案 1 :(得分:1)
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
答案 2 :(得分:0)
您无法在头文件中触发方法。它们需要位于实现文件中的方法内。标题(.h)文件用于向编译器等声明内容,实现文件(.m)是应该发生魔法的地方。
做这样的事情
您的头文件..
#import <UIKit/UIKit.h>
@interface BIDViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *numberField;
@property (weak, nonatomic) IBOutlet UITextField *nameField;
- (IBAction)textFieldDoneEditing:(id)sender;
@end
您的实施文件(.m)
#import "BIDViewController.h"
@implementation BIDViewController
- (IBAction)someMethodOrAction:(id)sender {
[self.nameField resignFirstResponder];
[self.numberField resignFirstResponder];
}
@end