键盘iPhone-Portrait-NumberPad找不到支持类型4的键盘;使用3876877096_Portrait_iPhone-Simple-Pad_Default

问题描述 投票:106回答:14

我已经为iPhone和SDK下载了iOS 8 Gold Master。

我测试了应用程序,它工作正常,除了一件事。

我有一个文本字段,如果用户想要键入内容,则会出现数字键盘,此外,当键盘显示时,自定义按钮会添加到空白区域。

- (void)addButtonToKeyboard
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        // create custom button
        UIButton * doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
        doneButton.frame = CGRectMake(-2, 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(saveNewLead:) forControlEvents:UIControlEventTouchUpInside];

        // locate keyboard view
        UIWindow * tempWindow = [[[UIApplication sharedApplication] windows]objectAtIndex:1];
        UIView* keyboard;
        for(int i=0; i<[tempWindow.subviews count]; i++) 
        {
            keyboard = [tempWindow.subviews objectAtIndex:i];

            // keyboard view found; add the custom button to it
            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
                if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
                    [keyboard addSubview:doneButton];
            } else {
                if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
                    [keyboard addSubview:doneButton];
            }
        }
    }

}

到目前为止这个工作正常。

首先,我收到了这个警告:

键盘iPhone-Portrait-NumberPad找不到支持类型4的键盘;使用3876877096_Portrait_iPhone-Simple-Pad_Default

那个自定义按钮也没有显示,我想因为这两行:

if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)

if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)

有什么建议?

iphone ios8
14个回答
10
投票

我也有这个问题,并找到了解决方案。

以下是适用于iOS 8.0以及以下版本的代码。

我在iOS 7和8.0(Xcode Version 6.0.1)上测试过它

- (void)addButtonToKeyboard
    {
    // create custom button
    self.doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
            //This code will work on iOS 8.3 and 8.4. 
       if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.3) {
            self.doneButton.frame = CGRectMake(0, [[UIScreen mainScreen]   bounds].size.height - 53, 106, 53);
      } else {
           self.doneButton.frame = CGRectMake(0, 163+44, 106, 53);
      }

    self.doneButton.adjustsImageWhenHighlighted = NO;
    [self.doneButton setTag:67123];
    [self.doneButton setImage:[UIImage imageNamed:@"doneup1.png"] forState:UIControlStateNormal];
    [self.doneButton setImage:[UIImage imageNamed:@"donedown1.png"] forState:UIControlStateHighlighted];

    [self.doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];

    // locate keyboard view
    int windowCount = [[[UIApplication sharedApplication] windows] count];
    if (windowCount < 2) {
        return;
    }

    UIWindow *tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
    UIView *keyboard;

    for (int i = 0; i < [tempWindow.subviews count]; i++) {
        keyboard = [tempWindow.subviews objectAtIndex:i];
             // keyboard found, add the button
          if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.3) {

            UIButton *searchbtn = (UIButton *)[keyboard viewWithTag:67123];
            if (searchbtn == nil)
                [keyboard addSubview:self.doneButton];

            } else {   
                if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) {
              UIButton *searchbtn = (UIButton *)[keyboard viewWithTag:67123];
                   if (searchbtn == nil)//to avoid adding again and again as per my requirement (previous and next button on keyboard)
                [keyboard addSubview:self.doneButton];

        } //This code will work on iOS 8.0
        else if([[keyboard description] hasPrefix:@"<UIInputSetContainerView"] == YES) {

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

                if([[hostkeyboard description] hasPrefix:@"<UIInputSetHost"] == YES) {
                    UIButton *donebtn = (UIButton *)[hostkeyboard viewWithTag:67123];
                    if (donebtn == nil)//to avoid adding again and again as per my requirement (previous and next button on keyboard)
                        [hostkeyboard addSubview:self.doneButton];
                }
            }
        }
      }
    }
 }

>

- (void)removedSearchButtonFromKeypad 
    {

    int windowCount = [[[UIApplication sharedApplication] windows] count];
    if (windowCount < 2) {
        return;
    }

    UIWindow *tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];

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

           if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.3){
                [self removeButton:keyboard];                  
            } else if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) {
                  [self removeButton:keyboard];

             } else if([[keyboard description] hasPrefix:@"<UIInputSetContainerView"] == YES){

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

                if([[hostkeyboard description] hasPrefix:@"<UIInputSetHost"] == YES) {
                    [self removeButton:hostkeyboard];
                }
            }
        }
    }
}


- (void)removeButton:(UIView *)keypadView 
    {
    UIButton *donebtn = (UIButton *)[keypadView viewWithTag:67123];
    if(donebtn) {
        [donebtn removeFromSuperview];
        donebtn = nil;
    }
}

希望这可以帮助。

但是,我仍然收到这个警告:

键盘iPhone-Portrait-NumberPad找不到支持类型4的键盘;使用3876877096_Portrait_iPhone-Simple-Pad_Default

忽略这个警告,我得到了它的工作。如果你能从这个警告中得到解脱,请告诉我。


1
投票

我使用分发配置文件时遇到了同样的问题。检查您是否使用开发者资料


1
投票

为什么长代码而不使用UIToolbar?既然警告仍然存在?

UIToolbar适用于任何iOS版本,这是我的示例代码

UIToolbar *doneToolbar = [[UIToolbar alloc] initWithFrame:(CGRect){0, 0, 50, 50}]; // Create and init
doneToolbar.barStyle = UIBarStyleBlackTranslucent; // Specify the preferred barStyle
doneToolbar.items = @[
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], 
[[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(doneEditAction)] // Add your target action
]; // Define items -- you can add more

yourField.inputAccessoryView = doneToolbar; // Now add toolbar to your field's inputview and run
[doneToolbar sizeToFit]; // call this to auto fit to the view

- (void)doneEditAction {
    [self.view endEditing:YES];
}

1
投票

在您的iOS应用程序中找不到连接到OS X的数字键盘。因此,您只需在模拟器中取消选中“连接硬件键盘”选项,在以下路径中仅用于测试目的:

Simulator -> Hardware -> Keyboard -> Connect Hardware Keyboard

这将解决上述问题。

我想你也应该看到以下链接。它说在论坛帖子结尾的bug中是XCode

Reference


0
投票

也许你应该重置按钮的框架,我也有一些问题,并且nslog键盘视图如下:

iOS8上:

"<UIInputSetContainerView: 0x7fef0364b0d0; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x7fef0364b1e0>>"

before8:

"<UIPeripheralHostView: 0x11393c860; frame = (0 352; 320 216); autoresizesSubviews = NO; layer = <CALayer: 0x11393ca10>>"

-1
投票

好的,这是一个简单的解决方案,当我遇到类似的错误时,可以在iOS 9,iOS 8及以下版本的应用中显示和使用“完成”按钮。在运行应用程序并通过“View的层次结构”查看它(即,当应用程序在设备上运行并在Storyboard中检查您的视图时,单击调试区域栏中的“查看层次结构”图标)时,可以观察到键盘显示在与iOS 8及以下版本相比,iOS 9中的不同窗口必须加以考虑。 addButtonToKeyboard

- (id)addButtonToKeyboard
{
if (!doneButton)
{
   // create custom button
    UIButton * doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    doneButton.frame = CGRectMake(-2, 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(saveNewLead:) forControlEvents:UIControlEventTouchUpInside];
}

NSArray *windows = [[UIApplication sharedApplication] windows];
//Check to see if running below iOS 9,then return the second window which bears the keyboard   
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 9.0) {
return windows[windows.count - 2];
}
else {
UIWindow* keyboardWithDoneButtonWindow = [ windows lastObject];
return keyboardWithDoneButtonWindow;
    }
}

如果你愿意,这就是你如何从键盘中删除KeyboardButton。

- (void)removeKeyboardButton {

id windowTemp = [self addButtonToKeyboard];

if (windowTemp) {

    for (UIView *doneButton in [windowTemp subviews]) {
        if ([doneButton isKindOfClass:[UIButton class]]) {
            [doneButton setHidden:TRUE];
        }
    }
  }
}

136
投票

更新到最新的Xcode Beta后,我也遇到了这个问题。刷新模拟器上的设置,因此正在检测笔记本电脑(外部)键盘。如果你只是按:

iOS模拟器 - >硬件 - >键盘 - >连接硬件键盘

这样输入是UNchecked,然后软件键盘将再次显示。


39
投票

模拟器试图在Mac上找到一个数字小键盘,但找不到(MacBook Pro,MacBook Air和“普通/小型”键盘没有它)。您可以取消选择“连接硬件键盘”选项,或者只是忽略错误消息,它对应用程序没有负面影响。


12
投票

我在ios 8中使用xcode,只需在模拟器 - >硬件 - >键盘 - >连接硬件键盘中取消选中连接硬件键盘选项。

这将解决问题。


10
投票

去吧

iOS模拟器 - >硬件 - >键盘 - >取消选中“连接硬件键盘选项”。

这将解决问题。

执行上述步骤后,您的MAC键盘将无法工作,您必须使用模拟器键盘。


7
投票

我在Xcode 8.1和iOS 10.1中遇到了同样的问题。对我有用的是进入模拟器 - >硬件 - >键盘并取消选中连接硬件键盘。


5
投票

使用模拟器运行应用程序

iOS模拟器 - >硬件 - >键盘 - > iOS使用与OS X相同的布局

如果有人在他们的设备上运行他们的应用程序,这将解决问题


4
投票

进入模拟器 - >硬件 - >键盘并取消选中连接硬件键盘。

在我退出并重新启动模拟器之前,与上面的许多答案相同并没有改变。 xcode 8.2.1和Simulator 10.0。


3
投票

我有两个不同的原因得到了相同的错误消息,因此您可以将它们添加到调试清单中:

上下文:Xcode 6.4,iOS:8.4。我添加了一个带有自定义UIBarButtons的工具栏来加载UIKeyboardTypeNumberPad(Swift:UIKeyboardType.numberPad),即“Done”和“+/-”。我遇到这个问题的时候:

  1. 我的UIToolbar被声明为属性,但我忘记了显式地分配/初始化它。
  2. 我离开了最后一行,[myCustomToolbar sizeToFit];,听起来和霍尔顿的回答是同一个家族(我的代码在这里:https://stackoverflow.com/a/32016397/4898050)。

祝好运

© www.soinside.com 2019 - 2024. All rights reserved.