Iphone 添加到numpad的自定义按钮有问题

Iphone 添加到numpad的自定义按钮有问题,iphone,ios,Iphone,Ios,您好,我试图解散一个numpad键盘,它有一个自定义完成按钮实现。当我试图关闭它时,应用程序崩溃,出现以下错误 *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIButton键]:未识别的选择器已发送到实例0x7399b40” 下面是代码片段 // Snippet - (void)keyboardWillShow:(NSNotification *)notification { // create custom butt

您好,我试图解散一个numpad键盘,它有一个自定义完成按钮实现。当我试图关闭它时,应用程序崩溃,出现以下错误 *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIButton键]:未识别的选择器已发送到实例0x7399b40”

下面是代码片段

// Snippet
  - (void)keyboardWillShow:(NSNotification *)notification {  
      // create custom button
     doneButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
     doneButton.frame = CGRectMake(0, 163, 106, 53);
     doneButton.adjustsImageWhenHighlighted = NO;
     [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"]       forState:UIControlStateNormal];
     [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
     [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];


    // locate keyboard view
  UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;    
UITextField * tempTextField = (UITextField*)self.currentResponder;   //Current responder is the textfield which is clicked


for(int i=0; i<[tempWindow.subviews count]; i++) {
    keyboard = [tempWindow.subviews objectAtIndex:i];

    if([[[keyboard class]description] hasPrefix:@"UIPeripheralHostView"])
    {

        if(tempTextField.keyboardType == UIKeyboardTypeNumberPad)  
        {
            UIView *viewToInsertButtonInto = [[[[[[[[keyboard subviews] objectAtIndex:0] subviews]objectAtIndex:0]subviews]objectAtIndex:0]subviews]objectAtIndex:0];
            [viewToInsertButtonInto addSubview:self.doneButton];
        }

    }

}
当[TestExtfield辞职FirstResponder]时,应用程序崩溃;被执行

有人能帮忙吗。 谢谢 纳契克

你为什么要用这个日志

我认为你应该使用
NSLog(@“%@,self.faxTextField.text);

或使用

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;

}

你能告诉我什么是“键”吗?它是一个方法还是一个变量?你的按钮试图调用一个叫做“键”的选择器“。我认为它崩溃了,因为您正在使用%@在
doneButton:
方法中记录名为
faxTextField
的文本字段。不能在日志中打印文本字段。您所能做的就是使用
self.faxTextField.text
打印文本。另外,
self.currentResponder
是一个不能使用%@符号记录的文本字段。希望这对你有帮助。
NSLog(@"%@,%@  _________     %s",self.faxTextField,self.currentResponder,__FUNCTION__);
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;

}