2012-02-17 52 views
2

我正在使用iOSOpenDev为通知中心做一个应用程序。我在UIView上有一个UITextField,并且已经实现了UITextFieldDelegate协议。为什么iOS 5 WeeApp中没有UITextField清除按钮?

我的问题是textFieldShouldClear方法永远不会被点击UITextField中的清除按钮调用。其他接口方法,如shouldChangeCharactersInRange和textFieldShouldReturn被调用没有问题。

任何想法为什么界面方法永远不会被调用?

回答

0

确保文本框的委托是自:

theTextField.delegate = self; 

我听说UIActionSheet吸了UITextFieldDelegate协议,并通知中心可能会做同样的...

+0

textField的委托已经设置为self,但它没有区别。 – icecreamhead 2012-03-01 00:02:42

+0

找到任何更改UITextfield委托(除了将其设置为self的委托)并将其注释掉的内容。然后看看它是否有效。我会使用写入文件的东西,因为NSLog很难处理您的情况。 – 2012-04-17 11:48:10

1

我有这个问题当用户在屏幕上的其他地方点击时我解散键盘。我有一个手势识别器来查找点击,当检测到点击时,它会在文本字段中调用resignFirstResponder。不幸的是,这打破了清晰的按钮。

我所做的就是过滤水龙头以确保它们是表视图外,具有手动触发按钮,水龙头稍微复杂:

// In: - (void)handleTap:(UITapGestureRecognizer *)sender { 
// The user tapped outside a text field, drop the keyboard. 
// Unfortunately this normally breaks the clear button, so we'll check that the 
// tap is outside the table view (and therefore not on a clear button). 
BOOL inButton = CGRectContainsPoint(self.signInButton.bounds, [sender locationInView:self.signInButton]); 
BOOL inTable = CGRectContainsPoint(self.tableView.bounds, [sender locationInView:self.tableView]); 
if (!inTable && !inButton) { 

    BOOL didEndEditing = [self.view endEditing:NO]; 

    // But... if we were editing a field (& therefore the keyboard is showing), 
    // and if they tapped the sign in button, sign in. Not sure where the 
    // onSignIn event is getting lost. The button does highlight. But the 
    // call to endEditing seems to eat it. 
    if (didEndEditing && inButton) { 
     [self onSignIn:self.signInButton]; 
    } 
} 
0

继格雷厄姆心动的回答,我改变了我的resignFirstResponder呼吁:

[self.focusInput performSelector: @selector(resignFirstResponder) 
         withObject: nil 
         afterDelay: 0.2f]; 

现在键盘会按照预期自动隐藏在水龙头上,但清除按钮功能已恢复。

相关问题