问题:
解决方法:1、点击UITextField的其他区域,隐藏键盘,同时将UITextField的text值传给下一个ViewController
1、设置UITextFieldDelegate
2、UITextField初始化和SearchBook事件
_searchBook = [[UITextField alloc]initWithFrame:CGRectMake(30, 200, 260, 40)]; _searchBook.delegate = self; _searchBook.returnKeyType = UIReturnKeySearch; _searchBook.placeholder = @"关键字/标题/ISBN"; _searchBook.borderStyle = UITextBorderStyleRoundedRect; [_searchBook addTarget:self action:@selector(search) forControlEvents:UIControlEventEditingDidEndOnExit]; [self.view addSubview:_searchBook];3、TextFieldDidEndEditing代理方法:(传值)点击returnType按钮,将UITextField的text值赋值给下一个ViewController的属性
-(void)textFieldDidEndEditing:(UITextField *)textField { _bookSearchList = [[BookSearchList alloc]init]; _bookSearchList.anywords = _searchBook.text; }4、Search方法:(跳转)当UITextField结束退出后跳转到下一个ViewController
- (void)search{[self.navigationController pushViewController:_bookSearchList animated:YES];}
5、Touch方法:(触摸其他区域隐藏键盘)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches]anyObject]; if (touch.tapCount >= 1) { [_searchBook resignFirstResponder]; } }
本文介绍如何通过UITextField的代理方法及触摸事件实现键盘隐藏,并将输入的值传递给下一个ViewController,包括UITextFieldDelegate设置、触摸事件处理及ViewController间的值传递。
1882

被折叠的 条评论
为什么被折叠?



