1

我有一个只有数字的文本字段。我正在尝试在键盘上实现完成/取消按钮以摆脱键盘。

在模拟器中,当我选择文本字段输入金额时,出现以下错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-       
[durood keyboardWillShow:]: unrecognized selector sent to instance 0x7644900'
*** First throw call stack:
(0x1c93012 0x10d0e7e 0x1d1e4bd 0x1c82bbc 0x1c8294e 0xb914f9 0x1ced0c5 0x1c47efa 0xac5bb2     
0x3c5777 0x3be929 0x3c08a2 0x3c0931 0x3c097b 0x3ba117 0x123386 0x122e29 0x2e63c3 0x2e8442   
0x2df85a 0x2de99b 0x2e00df 0x2e2d2d 0x2e2cac 0x2daa28 0x47972 0x47e53 0x25d4a 0x17698 
0x1beedf9 0x1beead0 0x1c08bf5 0x1c08962 0x1c39bb6 0x1c38f44 0x1c38e1b 0x1bed7e3 0x1bed668 
0x14ffc 0x209d 0x1fc5 0x1)
libc++abi.dylib: terminate called throwing an exception

这是我的 h 文件中的代码:

#import <UIKit/UIKit.h>

int dcounter;
int total;
int enteramount;

@interface durood : UIViewController {

IBOutlet UILabel *dcount;
IBOutlet UILabel *dtotal;
IBOutlet UITextField *numberTextField;

这是我的 m 文件中要添加到键盘的额外按钮的代码:

[super viewDidLoad];

UIToolbar *numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
                       [[UIBarButtonItem alloc]initWithTitle:@"Cancel" 
style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)],
                       [[UIBarButtonItem  
alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                       [[UIBarButtonItem alloc]initWithTitle:@"Apply"  
style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
                       nil];
[numberToolbar sizeToFit];
numberTextField.inputAccessoryView = numberToolbar;
}

-(void)cancelNumberPad{
[numberTextField resignFirstResponder];
numberTextField.text = @"";
}

-(void)doneWithNumberPad{
NSString *numberFromTheKeyboard = numberTextField.text;
[numberTextField resignFirstResponder];
}

我错过了什么?任何帮助将不胜感激。键盘应如下所示:在此处输入图像描述

4

1 回答 1

1

durood崩溃来自于没有方法实现的事实keyboardWillShow:

您是否订阅通知,例如UIKeyboardWillShowNotification?您可能添加了一个@selector(keyboardWillShow),但实际上并没有创建方法实现。

于 2013-04-06T17:38:19.910 回答