Ios 当我点击返回键(xcode)时,键盘未重新调整

Ios 当我点击返回键(xcode)时,键盘未重新调整,ios,Ios,我正试图让键盘离开,当我按下应用程序上的返回键时,下面是我的.m代码: - (BOOL)textFieldShouldReturn:(UITextField *)textField{ [textField resignFirstResponder]; return YES; } 以及.h中的代码: - (BOOL)textFieldShouldReturn:(UITextField* )textField; 但是当我运行应用程序并按下返回键时,什么也没有发生。我做错了什么 my.h: #

我正试图让键盘离开,当我按下应用程序上的返回键时,下面是我的.m代码:

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

[textField resignFirstResponder];
return YES;

}
以及.h中的代码:

- (BOOL)textFieldShouldReturn:(UITextField* )textField;
但是当我运行应用程序并按下返回键时,什么也没有发生。我做错了什么

my.h:

#import <UIKit/UIKit.h> 
@interface ChemicalInfoViewController: UIViewController{
IBOutlet UIScrollView *ChemicalInforScroller;

}
@property (strong, nonatomic) IBOutlet UITextField *PPMForChlTextField;
@property (strong, nonatomic) IBOutlet UITextField *GallonsForChlTextField;
@property (strong, nonatomic) IBOutlet UITextField *PPMForAlkTextField;
@property (strong, nonatomic) IBOutlet UITextField *GallonsForAlkTextField;
@property (strong, nonatomic) IBOutlet UITextField *PPMForPHTextField;
@property (strong, nonatomic) IBOutlet UITextField *GallonsForPHTextField;
- (IBAction)SumbitCDI:(UIButton *)sender;
@property (strong, nonatomic) IBOutlet UILabel *PPMLabelForChl;
@property (strong, nonatomic) IBOutlet UILabel *GallonsLabelForChl;
@property (strong, nonatomic) IBOutlet UILabel *PPMLabelForAlk;
@property (strong, nonatomic) IBOutlet UILabel *GallonsLabelForAlk;
@property (strong, nonatomic) IBOutlet UILabel *PPMLabelForPH;
@property (strong, nonatomic) IBOutlet UILabel *GallonsLabelForPH;
@property (strong, nonatomic) IBOutlet UITextField *ChlorinePoundsTextField;
@property (strong, nonatomic) IBOutlet UITextField *GallonsForAlkDecreaser;
@property (strong, nonatomic) IBOutlet UITextField *PhPoundsTextField;
@property (strong, nonatomic) IBOutlet UITextField *AlkPoundsTextField;
@property (strong, nonatomic) IBOutlet UITextField *LbsForAlkDecreaser;
@property (strong, nonatomic) IBOutlet UITextField *PPMForAlkDecreaser;
@property (strong, nonatomic) IBOutlet UITextField *LbsForPhDecreaser;
@property (strong, nonatomic) IBOutlet UITextField *PPMForPhDecreaser;
@property (strong, nonatomic) IBOutlet UITextField *GallonsForPhDecreaser;
- (IBAction) clickedBackground;
@interface ChemicalInfoViewController : UIView <UITextField>
@end

.h
中,删除:

- (BOOL)textFieldShouldReturn:(UITextField* )textField;
考虑到在您的
.h
中,您遵守以下协议,它将正常工作:

@interface yourViewController : UIView <UITextFieldDelegate>
关于
@end
的编辑:

.m
中,在底部添加一个
@end
;因此,它变成(滚动到最底部):


您没有为文本字段设置代理

在“viewDidLoad”中添加

_chloreneboundstextfield.delegate=self

_GallonsForAlkDecreaser.delegate=self

_PhPoundsTextField.delegate=self

_AlkPoundsTextField.delegate=self

_LbsForAlkDecreaser.delegate=self

_PPMForAlkDecreaser.delegate=self

_LbsForPhDecreaser.delegate=self

_PPMForPhDecreaser.delegate=self

_GallonsForPhDecreaser.delegate=self


由于某种原因,这些方法似乎都不起作用,但我最终做的是创建一个didenonexit操作,并在该操作下为每个文本字段退出键盘

这样仍然不起作用。谢谢你,还有其他想法吗?@Jake我刚刚测试过它。这对我有用。yourTextField是您的文本字段;如果您有一个名为“textField”的textField,则将其替换为它。@Jake从.h中删除该方法;按照回答中提到的协议,那么这个方法应该被调用,键盘应该被放弃。@Jake它在哪里说的?小时还是分钟?请出示您的.h文件。通常在缺少
}
时会发生这种情况。@Jake Here:
@interface-ChemicalInfoViewController:UIView
应该是
@interface-ChemicalInfoViewController:UIView
并且在.m中缺少
@end
@interface yourViewController : UIView <UITextFieldDelegate>
yourTextField.delegate = self;
@implementation ChemicalInfoViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {

}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
[ChemicalInforScroller setScrollEnabled:YES];
[ChemicalInforScroller setContentSize:CGSizeMake(320, 1000)];
self.textField.delegate = self;

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];

}


- (IBAction) clickedBackground {

[self.view endEditing:YES];

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

[textField resignFirstResponder];
return YES;

}

@end //Here :-)