iphone - 尝试在数字键盘上实现完成/取消按钮,但在模拟器中选择文本字段时会出现错误

标签 iphone ios objective-c xcode

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

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

*** 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];
}

我错过了什么?任何帮助将不胜感激。键盘应如下所示:enter image description here

最佳答案

崩溃是因为 durood 没有 keyboardWillShow: 的方法实现。

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

关于iphone - 尝试在数字键盘上实现完成/取消按钮,但在模拟器中选择文本字段时会出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15853961/

相关文章:

iphone - AFNetworking POST并取回数据

ios - 无法在 iOS 11 GM 中更改多个文本字段颜色

objective-c - 如何将文本插入到当前光标位置的 UITextField 中?

iphone - "Overscroll"一个 TableView

ios - 位置管理器 :didExitRegion: a big delay of firing when transmitting is stopped

iphone - 在iPhone游戏中隐藏图像的一部分

objective-c - 将 map 居中到可见区域

objective-c - 带有 iPhone5(8.0) 模拟器的 xcode 6 - 当我运行项目时显示 Clang 错误

iphone - 左右滑动 UIView

iphone - 我应该如何将Subview添加到cell.contentView?