如何找出UITextField导致UIKeyboardWillShowNotification的原因? [英] How to find out what UITextField caused a UIKeyboardWillShowNotification?
问题描述
我正在尝试在我的应用程序中使用自定义键盘,但在尝试将其限制为一个特定的UITextField时遇到问题。
I am trying to use a customized keyboard in my application, but I am hitting problems when trying to restrict it to one particular UITextField.
我的代码基于此Xcode项目(最初在此博客)。该代码将自定义UIButton(表示小数点)添加到UIKeyboardTypeNumberPad键盘视图中。它通过订阅UIKeyboardWillShowNotification并在出现时修改键盘来实现。
I based my code on this Xcode project (originally found on this blog). That code adds a custom UIButton (representing a 'decimal point') into the UIKeyboardTypeNumberPad keyboard view. It does it by subscribing to UIKeyboardWillShowNotification and modifying the keyboard when it appears.
Xcode项目工作得很好,但是当我添加一个额外的UITextField时,自定义键被放入该文本字段的键盘,即使我为该文本字段选择了完全不同的键盘类型。
That Xcode project works great, but when I add an extra UITextField, the custom key gets put into the keyboard for that text field too, even though I have selected a completely different keyboard type for that text field.
我试图注册只看到来自一个的UIKeyboardWillShowNotification通知特别是UITextField,但似乎不起作用:
I attempted to register to only see UIKeyboardWillShowNotification notifications from the one particular UITextField, but that doesn't seem to work:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:exampleViewController.textField];
我还试图检查传递给keyboardWillShow的NSNotification里面的对象,但不幸的是它指的是键盘,而不是导致键盘出现的UI控件。
I also tried to inspect the object inside the NSNotification passed to keyboardWillShow, but unfortunately it refers to the keyboard, not the UI control that caused the keyboard to appear.
2009-10-21 19:50:22.205 Example[6302:207] NSConcreteNotification 0x321ebd0 {name = UIKeyboardWillShowNotification; userInfo = {
UIKeyboardAnimationCurveUserInfoKey = 0;
UIKeyboardAnimationDurationUserInfoKey = 0.300000011920929;
UIKeyboardBoundsUserInfoKey = NSRect: {{0, 0}, {320, 216}};
UIKeyboardCenterBeginUserInfoKey = NSPoint: {160, 588};
UIKeyboardCenterEndUserInfoKey = NSPoint: {160, 372};
}}
我是否误解了addObserver接口?当然必须有一种方法来订阅来自特定UI控件的通知吗?
Am I misunderstanding the addObserver interface? Surely there must be a way to subscribe to notifications from a particular UI control?
有没有人有关于如何实现此目的的任何其他建议?
Has anybody got any other suggestions on how to achieve this?
推荐答案
无法获得上述任何功能。不得不手动完成:
Couldn't get any of the above to work. Had to do it manually:
if ([companyName isFirstResponder]) {
// ...............
}
else if ([notes isFirstResponder]) {
//.............
}
}
这篇关于如何找出UITextField导致UIKeyboardWillShowNotification的原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!