我试图在我的应用程序中使用自定义键盘,但在尝试将其限制为一个特定的 UITextField 时遇到问题。
我的代码基于这个 Xcode 项目 http://billabonger.net/blog/wp-content/uploads/2009/01/customnumberpad-example.zip(最初发现于这个博客 http://billabonger.net/blog/2009/01/add-a-decimal-to-uitextfield-number-pad-keyboard/)。该代码将自定义 UIButton(代表“小数点”)添加到 UIKeyboardTypeNumberPad 键盘视图中。它通过订阅 UIKeyboardWillShowNotification 并在键盘出现时修改键盘来实现。
该 Xcode 项目运行良好,但当我添加额外的 UITextField 时,自定义键也会放入该文本字段的键盘中,即使我为该文本字段选择了完全不同的键盘类型。
我尝试注册以仅查看来自一个特定 UITextField 的 UIKeyboardWillShowNotification 通知,但这似乎不起作用:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:exampleViewController.textField];
我还尝试检查传递给keyboardWillShow的NSNotification内部的对象,但不幸的是它指的是键盘,而不是导致键盘出现的UI控件。
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 控件的通知吗?
有人对如何实现这一目标有任何其他建议吗?