何时触摸 tableview.How 以外的区域以关闭 tableView?
when touches outside the tableview.How to dismiss the tableView?
如何在我们单击视图时关闭 table 视图?我正在使用触摸开始 method.but 它不起作用?
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touches began");
UITouch *touch = [touches anyObject];
if(touch.view!=myTableView){
myTableview.hidden = YES;
}
}
当我们点击 view.i 我有三个 table 视图时如何禁用 table?
试试这个
ViewDidLoad
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handelGesture:)];
[self.view addGestureRecognizer:tap];
动作方法
- (void) handelGesture:(UITapGestureRecognizer*)sender
{
myTableview.hidden = YES;
}
希望对您有所帮助。
如果您根据要求修改了此代码,请检查它是否正常工作谢谢
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSArray *subviews = [self.view subviews];
for (id objects in subviews) {
if ([objects isKindOfClass:[UITextField class]]) {
UITextField *theTextField = objects;
if ([objects isFirstResponder]) {
[theTextField resignFirstResponder];
}
}
}
}
如何在我们单击视图时关闭 table 视图?我正在使用触摸开始 method.but 它不起作用?
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touches began");
UITouch *touch = [touches anyObject];
if(touch.view!=myTableView){
myTableview.hidden = YES;
}
}
当我们点击 view.i 我有三个 table 视图时如何禁用 table?
试试这个
ViewDidLoad
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handelGesture:)];
[self.view addGestureRecognizer:tap];
动作方法
- (void) handelGesture:(UITapGestureRecognizer*)sender
{
myTableview.hidden = YES;
}
希望对您有所帮助。
如果您根据要求修改了此代码,请检查它是否正常工作谢谢
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSArray *subviews = [self.view subviews];
for (id objects in subviews) {
if ([objects isKindOfClass:[UITextField class]]) {
UITextField *theTextField = objects;
if ([objects isFirstResponder]) {
[theTextField resignFirstResponder];
}
}
}
}