Form Sheet的ViewController无法自动隐藏键盘的解决方法
来源:互联网 发布:apache https 编辑:程序博客网 时间:2024/05/17 04:13
Form Sheet的ViewController无法自动隐藏键盘的解决方法
在实现登录,注册等iPad界面时,经常要用到FormSheet形式的ViewController。最简单的比如说登录界面,有用户名,密码,登录按钮组成,即两个UITextField,一个UIButton组成,希望输入用户名,按键盘的return键时,跳到输入密码,输入密码后按键盘的return键,键盘消失,进入登录处理。在非FormSheet形式的时候,界面处理跟预期一致。但当是FormSheet形式的时候,键盘隐藏不了。代码如下
1、第一个ViewController有一个按钮,弹出一个FormSheet风格的视图(部分代码)。
- (IBAction)buttonPressed:(id)sender {
DemoViewController *demoViewController = [[DemoViewControlleralloc] initWithNibName:@"DemoViewController" bundle: nil];
UINavigationController *nav = [[[UINavigationControlleralloc] initWithRootViewController: demoViewController]autorelease];
nav.modalPresentationStyle =UIModalPresentationFormSheet;
[demoViewController release];
[selfpresentViewController: nav animated: YES completion: nil];
}
2、弹出的视图代码(部分代码):
- (void)viewDidLoad
{
[superviewDidLoad];
// Do anyadditional setup after loading the view from its nib.
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDonetarget:self action:@selector(done)] autorelease];
_tfName .delegate =self;
_tfPassword.delegate =self;
}
- (void)done{
[selfdismissViewControllerAnimated: YES completion: nil];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
if (textField ==_tfName) {
[_tfPasswordbecomeFirstResponder];
returnYES;
}
[textField resignFirstResponder];
returnYES;
}
- (IBAction)buttonLoginPressed:(id)sender {
[_tfNameresignFirstResponder];
[_tfPasswordresignFirstResponder];
}
在http://stackoverflow.com/questions/3372333/ipad-keyboard-will-not-dismiss-if-modal-view-controller-presentation-style-is-ui
上找到了解决方法:
Be careful ifyou are displaying the modal with a UINavigationController. You then haveto set the disablesAutomaticKeyboardDismissal on thenavigation controller and not on the view controller. You can easily do thiswith categories.
File:UINavigationController+KeyboardDismiss.h
#import <Foundation/Foundation.h>
@interfaceUINavigationController(KeyboardDismiss)
-(BOOL)disablesAutomaticKeyboardDismissal;
@end
File:UINavigationController+KeyboardDismiss.m
#import "UINavigationController+KeyboardDismiss.h"
@implementationUINavigationController(KeyboardDismiss)
-(BOOL)disablesAutomaticKeyboardDismissal
{
returnNO;
}
@end
Do not forget to import the category in the file where you use theUINavigationController.
将上面的类别方法放在使用UINavigationController的地方就可以了。
- Form Sheet的ViewController无法自动隐藏键盘的解决方法
- EBS无法打开form及form乱码的解决方法
- 隐藏文件无法显示的解决方法
- WIN7的菜单栏无法隐藏解决方法
- 以popup方式呈现的viewcontroller中键盘消失的解决方法
- ViewController无法自动销毁
- WPS菜单栏自动隐藏的解决方法
- 任务栏无法自动隐藏的问题处理
- cocos2d-x1.0 无法隐藏键盘的解决方案!
- 关于图文发表界面textview无法隐藏键盘的解决方案
- Android结束Activity时键盘无法隐藏的问题
- 页面跳转 和虚拟键盘的自动隐藏
- 点击Editview以外的点击事件,自动隐藏虚拟键盘
- android隐藏软键盘 不自动弹出键盘的方法
- 隐藏CCTextFieldTTF的键盘
- Android键盘的隐藏
- 隐藏键盘的方法
- 键盘隐藏的处理
- linux下使用c进行线程操作
- Android驱动开发之earlysuspend睡眠模式编程总结
- 解决QT中中文字符乱码问题
- ASP.NET Integration with IIS 7
- 扫描程序设计说明文档
- Form Sheet的ViewController无法自动隐藏键盘的解决方法
- 纯虚函数
- ZJUT 1005 幻方
- poj3261
- 利用TWAIN-实现与图像输入设备的通讯
- 表格— — 表格边框的颜色
- Unity3d 游戏场景优化 - LOD(Level-of-detail)
- HTTP请求头和响应头
- python写的冒泡排序