- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个按钮和一个文本框。我只想在单击按钮时键盘消失。为什么我下面的代码不起作用。
更新:我看到了一些关于文件所有者的信息。我不明白如何在 XCode4 中执行此操作我使用 Storyboard,但看不到任何文件所有者图标。
更新 2:我找到了一个图 http://www.techotopia.com/index.php/Writing_iOS_4_Code_to_Hide_the_iPhone_Keyboard_%28Xcode_4%29但它在 XCode 4 上使用 XIB 文件而不是 Storyboard 。如何使用 Storyboard 来做到这一点?
我的ViewController.h
@interface myViewController : UIViewController <UITextFieldDelegate>
{
UITextField *myTextField;
}
@property (retain, nonatomic) IBOutlet UITextField *myTextField;
myViewController.m
- (BOOL)textFieldShouldReturn: (UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
myTextField.delegate = self;
}
- (IBAction)DoCalc:(id)sender {
// ...
}
最佳答案
检查您写入 myViewController.m 的 textFieldShouldReturn 函数是否被调用。在其中设置一个断点,然后运行模拟器。按键盘上的返回键。如果程序没有中断,则不会调用您编写的函数。
如果是,那是因为您没有将 UIResponder 职责委派给您的 View Controller 。确保您将响应者职责委派给您正在使用的 UITextField 的 myViewController 类。
在 Storyboard 中,您可以通过从 UITextField 小部件按住 control 并拖动到场景下方的黄色球体,然后从出现的上下文菜单中选择“委托(delegate)”来完成此操作。
关于iphone - textFieldShouldReturn 不起作用(在 XCode 4 上使用 Storyboard),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9518281/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!