touchesBegan没有被调用

时间:2015-06-12 00:50:46

标签: ios objective-c uitableview uitextfield touchesbegan

我在serialize中有一些UITextFields,当用户点击其他地方时,我正试图解除键盘问题。这是我的代码:

static UITableVieweCells

当我在其他地方录音时,我没有得到任何- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; NSLog(@"touch began"); } 。我做错了什么?`

然后我尝试了NSLogsself.view.userInteractionEnabled = YES;,但他们都没有用。

2 个答案:

答案 0 :(得分:0)

你的触摸可能被桌面视图细胞吞噬了。尝试将键盘解除代码放在tableView:didSelectRowAtIndexPath:的表视图委托上。

编辑:

也许那时你应该使用它和手势识别器的某种组合:

UITapGestureRecognizer *navBarTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard:)];
[self.navigationController.navigationBar addGestureRecognizer:navBarTap];

UITapGestureRecognizer *tableViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard:)];
[self.tableView addGestureRecognizer:tableViewTap];

答案 1 :(得分:0)

在UIScrollview中没有调用Touchesbegan,UITableview是uiScrollview的子类,所以make UITableview的subClass并实现所有

$('#designation').change(function(){
    var desg = $(this).val();
    if(desg) {
        $( "#assign_whom" ).autocomplete({
            source: function (request, response) {
                $.ajax({
                    type: "post",
                    url:"assign_whom.php", // from this page I get the data list in the form of json.
                    data: {term:request.term,desg:$('#designation').val()},
                    dataType: 'json',
                    success: function(data) {
                        response(data);
                    }
                });
            },
            minLength: 1,
            focus: function( event, ui ) {
            return false;
            },
            select: function( event, ui ) {
            document.getElementById('assign_to').value=ui.item.id;
            return true;
            }
        });         
    }
});