【问题标题】:Custom keypad button in iphoneiphone中的自定义键盘按钮
【发布时间】:2010-03-26 11:05:07
【问题描述】:

当我想在我的应用程序页面的键盘(文本字段填充器)中使用自定义按钮时,我在 iphone 中遇到了问题。我在键盘中嵌入了一个名为 dot 的按钮,它看起来很好,但是当我单击它时,它应该转到我定义的操作。但它崩溃了。

- (void)sendDecimal:(id)sender {
    // Post a Notification that the Decimal Key was Pressed.
    [[NSNotificationCenter defaultCenter] postNotificationName:@"DecimalPressed" object:nil];   
}

它一直运行到应用程序尝试向我不知道可能是例程或函数或方法发送通知。

有人可以在这方面帮助我吗?

谢谢

编辑

这是错误信息:

-[UITableView addDecimal:]: unrecognized selector sent to instance 0x4051e00 
2010-03-26 16:08:42.272 app[2855:20b]

Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[UITableView addDecimal:]: unrecognized selector sent to instance
0x4051e00' 

编辑

我已经定义了addDecimal选择器,这里是代码......

- (void)viewDidAppear:(BOOL)animated    {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:tableView selector:@selector(addDecimal:) name:@"DecimalPressed" object:nil];

编辑

是的,我把它写成 [dot addTarget:self action:@selector(sendDecimal:) forControlEvents:UIControlEventTouchUpInside];

【问题讨论】:

  • 您可以从控制台复制并粘贴错误消息吗?这将非常有帮助。
  • *** -[UITableView addDecimal:]:无法识别的选择器发送到实例 0x4051e00 2010-03-26 16:08:42.272 app[2855:20b] *** 由于未捕获的异常而终止应用程序' NSInvalidArgumentException',原因:'*** -[UITableView addDecimal:]:无法识别的选择器发送到实例 0x4051e00'

标签: iphone button


【解决方案1】:

你有没有写过类似的东西

[YourButtonButton addTarget:self action:@selector(addDecimal:) forControlEvents:UIControlEventTouchUpInside];

然后换成

[YourButtonButton addTarget:self action:@selector(sendDecimal:) forControlEvents:UIControlEventTouchUpInside];

从你的评论中我猜这只是拼写错误或什么

【讨论】:

  • 实际上我已经从如何创建自定义按钮的示例中获取了源代码,它在那里工作正常,因为他们在主应用程序委托文件中定义它,但我有一个应用程序,我必须做在 viewControllers 上。所以我将这些组合在一起,这样我就不必更改应用程序的主要委托文件中的任何内容。我希望我有点清楚,对不起,如果仍然没有:(
【解决方案2】:

解决问题的人

错误

[[NSNotificationCenter defaultCenter] addObserver:tableView selector:@selector(addDecimal:) name:@"DecimalPressed" object:nil];

解决:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addDecimal:) name:@"DecimalPressed" object:nil];

把 addObserver 放到 self 而不是 tableview

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-09
    • 1970-01-01
    • 2010-12-03
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多