我在一个视图控制器上有多个文本字段。我的.m和.h在下面。我是Xcode和Objective-C的新手,所以如果这只是一个愚蠢的错误,请好心。
·H:
#import <UIKit/UIKit.h>
@interface MainUI : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *letters;
@property (weak, nonatomic) IBOutlet UISegmentedControl *par;
@property (weak, nonatomic) IBOutlet UISegmentedControl *basicSym;
@property (weak, nonatomic) IBOutlet UITextField *numLetters;
@property (weak, nonatomic) IBOutlet UIButton *mainBack;
@property (weak, nonatomic) IBOutlet UIButton *mainNext;
@end
的.m:
#import "MainUI.h"
@interface MainUI ()
@end
@implementation MainUI
- (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.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)textFieldShouldReturn: (UITextField*)theTextField {
if (theTextField == self.textField) {
[theTextField resignFirstResponder];
}
return YES;
}
@end
错误发生在if (theTextField == self.textField) {
帮助吗?
答案 0 :(得分:0)
如果你只是试图让键盘在光标在文本字段中时按下Return键时消失,这应该就足够了:
- (BOOL)textFieldShouldReturn: (UITextField*)theTextField {
[theTextField resignFirstResponder];
return YES;
}