作者:承志68694849 | 来源:互联网 | 2023-09-08 17:18
SoIhavethisUITableViewthatcontainsfewrows,whenclickedonarow,anotherUIViewControlleri
So I have this UITableView
that contains few rows, when clicked on a row, another UIViewController
is pushed with the specific row details. My problem is that I want to dismiss keyboard with any touch on the screen (also on the UITableView
), but when I do it, and click on the UITableView
row, the keyboard dismisses, but the didSelectRow
method is not working. It wont push the new ViewController
once clicked on the cell.
所以我有这个包含几行的UITableView,当点击一行时,另一个UIViewController被推送到特定的行细节。我的问题是我想用屏幕上的任何触摸(也在UITableView上)来解除键盘,但是当我这样做,并且单击UITableView行时,键盘会解除,但didSelectRow方法不起作用。一旦点击单元格,它就不会推动新的ViewController。
Also the other way around, once I change it, you can click on the TableView cell, the keyboard dismiss and the other ViewController is pushed, but the touch on any other place is not dismissing the keyboard.
另一方面,一旦我改变它,你可以点击TableView单元格,键盘消除,另一个ViewController被推,但任何其他地方的触摸不解除键盘。
What should I do?
我该怎么办?
- (IBAction)hideKeyboard:(id)sender
{
[tfFoodsSearchQuery resignFirstResponder];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isKindOfClass:[UITableView class]])
{
// we touched a button, slider, or other UIControl
return YES; // handle the touch
}
NSLog(@"Touch");
return NO; // ignore the touch
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(hideKeyboard:)];
[self.view addGestureRecognizer:tap];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)];
gestureRecognizer.delegate = self;
[self.tvFoods addGestureRecognizer:gestureRecognizer];
}
Thanks!
2 个解决方案