前言
最近在寫一個商品的分類頁面,導(dǎo)航欄有一個搜索框,點擊空白頁面,收回鍵盤,在tableview添加了手勢,成功收回鍵盤.但是,,,,,,,,,cell點擊事件無法響應(yīng)了,怎么辦呢?
方法一
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(tap)];
tap.cancelsTouchesInView = NO; //切記,否則cell不能點擊 ,collectionview同樣如此
[tableV addGestureRecognizer:tap];
方法二
響應(yīng)連
添加uitableview分類 重寫hitTest:(CGPoint)point withEvent:(UIEvent *)event方法
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
id view = [super hitTest:point withEvent:event];
if (![view isKindOfClass:[UITextField class]]) {
[self endEditing:YES];
return self;
}
return view;
}
這段代碼的意思就是點擊的是tableview就結(jié)束編輯并且返回tableview本身,這樣就不影響了tableview本身的操作,然后點擊的是tableview的子視圖的時候就返回子視圖就行了。
注: 以上方法同樣適用于collectionview