私はInterface Builderで以下のメソッドを使用する方法を知っています。プログラムでTextFieldのキーボードを閉じる
-(void)dismissKeyboard
{
[testTextField resignFirstResponder];
}
こうして、キーボードの外側の領域に触れるか、「戻る」をタップすると、キーボードは閉じます。
しかし、私はコードでそれをすべて行う方法を知らない。ありがとう、教えてください。
は、ここで、ここでの.h
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
{
UITextField *testTextField;
}
@property (nonatomic,retain) UITextField *testTextField;
@end
です.M
#import "SecondViewController.h"
@implementation SecondViewController
@synthesize testTextField;
- (void)viewDidLoad
{
[super viewDidLoad];
UITextField *tempTextField = [[UITextField alloc] init];
self.testTextField = tempTextField;
testTextField.frame = CGRectMake(100, 150, 200, 30);
testTextField.placeholder = @"Test";
testTextField.backgroundColor = [UIColor whiteColor];
testTextField.textColor = [UIColor blackColor];
[self.view addSubview:testTextField];
}
のviewDidLoadでこのコードをキーボードを辞任すべきである。.. '[tempTextField setDelegate:自己];' – DefenestrationDay
@DefenestrationDayあなたの答えは正しいです! – Shinigamae