我有一个 textView,其提交按钮被键盘重叠,所以我试图添加一个侦听器,用于当用户点击屏幕上的其他任何地方以摆脱键盘时。
我正在尝试将这样的代码添加到我的控制器中:
-(void)touchesBegan:(NSSet *) touches withEvent:(UIEvent *)event
{
[textView resignFirstResponder];
}
但这给出了未声明 textView 的语法错误。但这很令人困惑,因为我已经将 textView 添加到了屏幕上。
这是代码:
#import "FeedbackController.h"
@interface FeedbackController ()
@end
@implementation FeedbackController
- (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)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)touchesBegan:(NSSet *) touches withEvent:(UIEvent *)event
{
[textView resignFirstResponder];
}
- (IBAction)submitFeedback:(id)sender {
NSLog(@"This is a test hello");
}
@end
这是屏幕的样子:
知道如何尝试正确引用 textView 吗?以及如何在触摸屏幕的其他部分时使键盘消失?
谢谢!