2010-03-26 32 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