试图找到哪个文本字段是活动的ios [英] Trying to find which text field is active ios

查看:72
本文介绍了试图找到哪个文本字段是活动的ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在键盘上升时移动视图时,我试图找到哪个文本字段处于活动状态。我试图在我的viewcontroller中从scrollview的子视图设置一个属性。

I am trying to find which textfield is active for when the I move the view when the keyboard rises. I am trying to set a property in my viewcontroller from the subview of a scrollview.

这是我用来在scrollview中显示视图的代码

This is the code I use to display the view in the scrollview

-(void)displayView:(UIViewController *)viewController{

[[viewFrame subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; 
[viewFrame scrollRectToVisible:CGRectMake(0, 0, 1, 1)
                        animated:NO];

[viewFrame addSubview: viewController.view];

_currentViewController = viewController;
}

- 编辑 -

我改变了对这个问题的思考方式。对不起,我发布时问题含糊不清。当时我很精疲力竭,这在我脑海中是有道理的。

I have changed my way of thinking about this problem. Sorry for the question being ambiguous when I posted it. I was exhausted at the time and it made sense in my head.

一个不同但相似的问题:是否有一个UITextArea和UITextView的共同子类将给我第一个响应者的起源?或者在找到原点之前还需要检查firstResponder的类吗?

A different but similar question: Is there a common subclass of both UITextArea and UITextView that will give me the origin of the firstResponder? Or will I have to check also the class of the firstResponder before I can find the origin?

推荐答案

你需要搜索一个已成为第一响应者的对象。第一响应者对象是使用键盘的人(实际上,他是一个具有用户输入焦点的人)。要检查哪个文本字段使用键盘,请迭代文本字段(或仅覆盖所有子视图)并使用 isFirstResponder 方法。

You need to search for an object that has become a first responder. First responder object is the one using the keyboard (actually, it is he one having focus for user input). To check which text field uses the keyboard, iterate over your text fields (or just over all subviews) and use the isFirstResponder method.

编辑:
根据要求提供示例代码,假设所有文本字段都是视图控制器视图的子视图:

As requested, a sample code, assuming all text fields are a subview of the view controller's view:

for (UIView *view in self.view.subviews) {
    if (view.isFirstResponder) {
        [self doSomethingCleverWithView:view];
    }
}

这篇关于试图找到哪个文本字段是活动的ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆