在我的应用程序中,当我开始滚动UITableView时,我想隐藏键盘.我在互联网上搜索这个,大多数答案是子类化UITableView(http://stackoverflow.com/questions/3499810/tapping-a-uiscrollview-to-hide-the-keyboard).
我做了子类但它不起作用.
#import <UIKit/UIKit.h>
@protocol MyUITableViewDelegate <NSObject>
@optional
- (void)myUITableViewTouchesBegan;
@end
@interface MyUITableView : UITableView <UITableViewDelegate, UIScrollViewDelegate> {
id<MyUITableViewDelegate> delegate;
}
@end
Run Code Online (Sandbox Code Playgroud)
.m文件
#import "MyUITableView.h"
@implementation MyUITableView
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
NSLog(@"delegate scrollView"); //this is dont'work
[super scrollViewDidScroll:scrollView];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"delegate myUITableViewTouchesBegan"); // work only here
[delegate myUITableViewTouchesBegan];
[super touchesBegan:touches withEvent:event];
}
- (void)dealloc {
...
Run Code Online (Sandbox Code Playgroud)
我像这样使用这个类.但委托函数myUITableViewTouchesBegan在ViewController中不起作用
.H
#import <UIKit/UIKit.h>
#import "MyUITableView.h"
@interface FirstViewController : UIViewController <UITableViewDelegate, UISearchBarDelegate, MyUITableViewDelegate> {
MyUITableView *myTableView;
UISearchBar *searchBar;
}
@property(nonatomic,retain) …Run Code Online (Sandbox Code Playgroud) 我有一个UITableView与UITextFieldS作为细胞.当UITableView触摸背景时,我想解除键盘.我试图通过创建一个UIButton大小UITableView并将其放在后面来做到这一点UITableView.唯一的问题是,UIButton即使触摸在UITableView上,也能捕获所有触摸.我究竟做错了什么?
谢谢!
我正在开发具有大量的iPad应用程序UIViewControllers,UITableViews(与细胞accessoryViews的UITextFields)等等,等等很多的UIViewControllers导航层次结构中出现.
有很多不同的地方UITextFields出现,包括as UITableViewCell accessoryViews.
我想设计一种有效的策略,用于在用户触摸UITextField当前正在编辑的内部时解除键盘.我已经搜索了键盘消除技术但尚未找到解释一般键盘解除策略如何工作的答案.
例如,我喜欢这种方法,其中以下代码被添加到任何ViewController:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"* * * * * * * * *ViewControllerBase touchesBegan");
[self.view endEditing:YES]; // dismiss the keyboard
[super touchesBegan:touches withEvent:event];
}
Run Code Online (Sandbox Code Playgroud)
......但是这种技术并不涉及例如UITableView在显示器内发生触摸的情况.因此,我需要添加一些代码来endEditing在UITableView触摸等时调用等等.这意味着我的应用程序将被大量代码用于在UIElements触摸其他各种键盘时解除键盘.
我想我可以尝试识别触摸需要截取的所有不同的地方,键盘被解雇,但在我看来,在处理iOS键盘关闭事件的某处可能有更好的设计模式.
任何人都可以在这个问题上分享他们的经验,并推荐一种特定的技术来统一处理整个应用程序中的键盘解雇吗?
非常感谢