【问题标题】:how to solve Use of undeclared identifier 'UIKeyboard' error?如何解决使用未声明的标识符“UIKeyboard”错误?
【发布时间】:2012-10-23 10:52:53
【问题描述】:

我试图在不使用 UITextViewUITextField 的情况下显示 UIKeyboard。我正在按照以下源代码在我的应用程序中显示键盘。

 UIKeyboard *keyboard = [[[UIKeyboard alloc] initWithFrame: CGRectMake(0.0f, 220.0f, 320.0f, 216.0f)] autorelease];
[keyboard setReturnKeyEnabled:NO];
[keyboard setTapDelegate:editingTextView];

但代码显示以下错误,

Use of undeclared identifier 'UIKeyboard'
Use of undeclared identifier 'keyboard'

有人请帮忙解决这个错误吗?请告诉我这是在不使用UITextViewUITextField 的情况下显示键盘的正确方法吗?

【问题讨论】:

  • 因为你强行声明了。
  • @VakulSaini 你能告诉我清楚吗?谢谢。
  • 在智能中看到它(UIKeyboard)吗?
  • 当您不希望用户输入任何内容时,显示键盘的原因是什么?
  • @waheeda 请看我提出的这个问题stackoverflow.com/questions/12995514/…

标签: iphone ios keyboard uikeyboard


【解决方案1】:

你可以使用UIKeyInput委托。

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIKeyInput>

在您的ViewController.m 课程中。 return YES;canBecomeFirstResponder:

-(BOOL)canBecomeFirstResponder
{
    return YES; 
}

它将显示keyboard。但是如果没有UITextViewUITextField,你在哪里写。 写在UIView 上看这个逻辑-UIKeyInput- Displaying keyboard in iPhone without UITextField or UITextView

【讨论】:

  • 非常感谢朋友。现在我可以看到键盘了。我不允许用户输入任何文本。我想在这个键盘中添加一个 UIToolbar 作为 InputAccessoryView。我会试试这个,让你认识朋友。
  • 好的...很高兴帮助你!!
猜你喜欢
  • 2021-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-12
  • 2014-08-04
  • 2020-05-05
  • 2019-09-29
相关资源
最近更新 更多