2010-03-26 75 views
0

我在iphone中遇到了问题,当我想在我的应用程序页面的小键盘(文本字段填充)中使用自定义按钮时。我在键盘上嵌入了一个名为dot的按钮,它显示正常,但是当我点击它时,它应该转到我定义的操作。但它崩溃。iphone中的自定义小键盘按钮

- (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]; 

编辑

是的,我已经写了这个作为 [点addTarget:自我行动:@选择(sendDecimal :) forControlEvents:UIControlEventTouchUpInside]。

+0

您可以复制并粘贴在控制台中的错误信息?这将非常有帮助。 – 2010-03-26 11:06:57

+0

*** - [UITableView addDecimal:]:无法识别的选择器发送到实例0x4051e00 2010-03-26 16:08:42.272应用程序[2855:20b] ***终止应用程序,由于未捕获异常'NSInvalidArgumentException',原因:' *** - [UITableView addDecimal:]:无法识别的选择发送到实例0x4051e00' – 2010-03-26 11:10:24

+0

是一个拼写错误...? – 2010-03-26 11:14:33

回答

0

问题解决了,大家好

错误

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

解析:

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

看跌的addObserver自我,而不是实现代码如下

1

你写过类似

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

然后用

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

从您的评论更换我是guessint它只是拼写错误或东西

+0

实际上,我已经从如何创建自定义按钮的示例中获取源代码,并且它在那里工作正常,因为它们在主应用程序委托文件中定义它,但我有一个应用程序,我必须做的是在viewControllers上。所以我把这些结合起来,这样我就不必在应用程序的主要代理文件中改变任何东西。我希望我有点清楚,对不起,如果仍然没有:( – 2010-03-26 11:23:12