觸摸空白收起鍵盤,不影響tableview的響應

 1.//    觸摸空白收起鍵盤

    self.view.userInteractionEnabled = YES;

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fingerTapped:)];

//  加上這句不會影響你 tableview 上的 action (button,cell selected...)

    singleTap.cancelsTouchesInView = NO;

    [self.view addGestureRecognizer:singleTap];

-(void)fingerTapped:(UITapGestureRecognizer *)gestureRecognizer


{

    [self.view endEditing:YES];

    

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章