首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到支持键盘类型4的键盘iPhone-Portrait-NumberPad;使用3876877096_Portrait_iPhone-Simple-Pad_Default

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

Stack Overflow用户
提问于 2014-09-15 14:39:09
回答 15查看 134.7K关注 0票数 129

我已经下载了iPhone版和iOS版的Windows8黄金版。

我测试了这个应用程序,它运行良好,除了一件事。

我有一个文本字段,如果用户想要键入什么,就会出现一个数字键盘,此外,当键盘出现时,会在空白区域添加一个自定义按钮。

代码语言:javascript
复制
- (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];
            }
        }
    }

}

到目前为止,这个方法运行得很好。

首先,我得到这样的警告:

找不到支持类型4的键盘iPhone-肖像-数字键盘;使用3876877096_肖像_iPhone-简单键盘-默认键盘

那么自定义按钮也不会显示,我认为这是因为这两行代码:

代码语言:javascript
复制
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)

代码语言:javascript
复制
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)

有什么建议吗?

EN

回答 15

Stack Overflow用户

回答已采纳

发布于 2014-09-22 17:45:44

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

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

我已经在iOS 7和8.0 (Xcode6.0.1版)上进行了测试。

代码语言:javascript
复制
- (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];
                }
            }
        }
      }
    }
 }

代码语言:javascript
复制
- (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;
    }
}

希望这能有所帮助。

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

找不到支持类型4的键盘iPhone-肖像-数字键盘;使用3876877096_肖像_iPhone-简单键盘-默认键盘

忽略这个警告,我让它正常工作。如果你能从这个警告中得到缓解,请让我知道。

票数 10
EN

Stack Overflow用户

发布于 2014-09-21 06:54:27

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

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

因此该条目为UNchecked,则软键盘将再次显示。

票数 150
EN

Stack Overflow用户

发布于 2015-11-22 10:01:17

模拟器试图在苹果电脑上找到一个数字键盘,但没有找到(MacBook Pro,MacBook Air和"normal/small“键盘没有)。您可以取消选择Connect Hardware Keyboard选项或忽略该错误消息,它不会对应用程序产生负面影响。

票数 45
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25842168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档