首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITextFieldDelegate SecondView

UITextFieldDelegate SecondView
EN

Stack Overflow用户
提问于 2011-11-21 10:05:18
回答 2查看 1.3K关注 0票数 1

我正在使用iOS 5,并试图在UITextFieldDelegate中使用TextField,它的工作方式与我想要的完全一样(但就在第一个视图中)。我不明白,为什么它不能在下一个视图中工作。

例如,我创建了新项目(ViewController)。在那里,我添加了一个按钮,它连接到另一个视图(SecondViewController)。在SecondViewController中,我有一个TextField。对于这个textField,我想使用textFieldShouldReturn。但是,这个方法似乎没有被调用。据我所知,我应该用ViewDidLoad写代表。我应该写myTextField.delegate =self吗?但我觉得有些地方不对劲。我用了调试,总是在那个位置,我遇到了问题。你能告诉我,有什么问题吗?我如何解决这个问题?

提前谢谢.

下面是我的代码(它在第一个视图(ViewController)中工作)。不幸的是,这里没有(SecondViewController):

SecondViewController.h

代码语言:javascript
复制
@interface SecondViewController : UIViewController<UITextFieldDelegate>

@property (strong, nonatomic) IBOutlet UITextField *myTextField;

@end

SecondViewController.m

代码语言:javascript
复制
@implementation SecondViewController

@synthesize myTextField;


- (void)viewDidLoad{

    [super viewDidLoad];

    myTextField.delegate = self; // here i get the problem
}

-(BOOL) textFieldShouldReturn:(UITextField *)textField{   // this method is not being called


    [textField resignFirstResponder];
    NSLog(@"is called!");
    NSString *valueMyTextField = myTextField.text;
    NSLog(@"%@", valueMyTextField);

    return YES;
}
EN

回答 2

Stack Overflow用户

发布于 2011-11-22 12:30:35

问题解决了..。)问题是从firstViewsecondView的连接。如果要添加控制器,请不要使用addSubView!使用presentModalViewController :)希望它有帮助,以防你和我有同样的问题。

票数 2
EN

Stack Overflow用户

发布于 2011-11-21 10:21:55

在nib文件中,请检查是否选中了文本字段的自动启用返回键复选框。

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

https://stackoverflow.com/questions/8210083

复制
相关文章

相似问题

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