UIActionSheet在iOS 7,SDK 7中关闭后,键盘隐藏并再次显示

UIActionSheet在iOS 7,SDK 7中关闭后,键盘隐藏并再次显示,第1张

概述我在ViewController中创建一个UIActionSheet.我还添加了代码来捕获UIKeyboardWillShowNotification和UIKeyboardWillHideNotification通知. 我的问题是当我解雇,我得到两个通知键盘隐藏和再次显示. 有人可以告诉我如何防止这个问题?它只发生在iOS 7中,并使用SDK 7构建 更新一些代码: 在viewDidLoad中,我 我在VIEwController中创建一个UIActionSheet.我还添加了代码来捕获UIKeyboarDWillShowNotification和UIKeyboarDWillHIDeNotification通知.

我的问题是当我解雇,我得到两个通知键盘隐藏和再次显示.
有人可以告诉我如何防止这个问题?它只发生在iOS 7中,并使用SDK 7构建

更新一些代码:

在vIEwDIDLoad中,我初始化一个按钮,当触摸按钮, *** 作表将被显示.

- (voID)vIEwDIDLoad{    [super vIEwDIDLoad];    UIbutton* button = [UIbutton buttonWithType:UIbuttonTypeRoundedRect];    button.frame = CGRectMake(10,50,100,30);    [button setTitle:@"Open menu" forState:UIControlStatenormal];    [button addTarget:self action:@selector(buttontouched) forControlEvents:UIControlEventtouchUpInsIDe];    [self.vIEw addSubvIEw:button];    UITextVIEw* textVIEw = [[UITextVIEw alloc] initWithFrame:CGRectMake(0,40)];    [self.vIEw addSubvIEw:textVIEw];    [textVIEw becomeFirstResponder];    [[NSNotificationCenter defaultCenter] addobserver:self                                             selector:@selector(keyboarDWillHIDe:)                                                 name:UIKeyboarDWillHIDeNotification                                               object:nil];    [[NSNotificationCenter defaultCenter] addobserver:self                                             selector:@selector(keyboarDWillShow:)                                                 name:UIKeyboarDWillShowNotification                                               object:nil];}- (voID)searchbarCancelbuttonClicked:(UISearchbar *) searchbar{    [searchbar resignFirstResponder];}- (voID) buttontouched{    UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"Action sheet" delegate:self cancelbuttonTitle:@"Cancel" destructivebuttonTitle:@"Destructive" otherbuttonTitles:@"Hello",nil];    [actionSheet showInVIEw:self.vIEw];}- (voID)keyboarDWillShow:(NSNotification*)notification{    NSLog(@"keyboarDWillShow");}- (voID)keyboarDWillHIDe:(NSNotification*)notification{    NSLog(@"keyboarDWillHIDe");}

我运行应用程序,键盘会显示,我触摸按钮,动作表显示.我通过触摸其上的任何按钮关闭 *** 作表,并记录打印:

keyboarDWillShow

keyboarDWillHIDe

keyboarDWillShow

解决方法 有一个非常简单的解决方案.应该在控制器的.m文件中添加私人本地类别
@interface UIActionSheet (NonFirstResponder)@end@implementation UIActionSheet (NonFirstResponder)- (BOol)canBecomeFirstResponder{    return NO;}@end

只有一个副作用.您的texFIEld / textVIEw在 *** 作列表中保留焦点.但这不是我想的一大麻烦.

也可以以相同的方式对UIActionSheet进行子类化.

总结

以上是内存溢出为你收集整理的UIActionSheet在iOS 7,SDK 7中关闭后,键盘隐藏并再次显示全部内容,希望文章能够帮你解决UIActionSheet在iOS 7,SDK 7中关闭后,键盘隐藏并再次显示所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1112418.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存