簡體   English   中英

iPhone中的自定義鍵盤按鈕

[英]Custom keypad button in iphone

當我想在我的應用程序頁面的鍵盤(文本字段填充)中使用自定義按鈕時,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];

你寫過類似的東西嗎

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

然后替換為

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

從您的評論中我很猜想這只是拼寫錯誤之類的

問題解決的家伙

錯誤

[[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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM