gpt4 book ai didi

iphone - textFieldShouldReturn 不起作用(在 XCode 4 上使用 Storyboard)

转载 作者:可可西里 更新时间:2023-11-01 05:06:43 25 4
gpt4 key购买 nike

我有一个按钮和一个文本框。我只想在单击按钮时键盘消失。为什么我下面的代码不起作用。

更新:我看到了一些关于文件所有者的信息。我不明白如何在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com