ios - 检查当前响应者?

标签 ios xcode cocoa-touch

我正在制作一个应用程序,需要使用多个带有数字键盘的文本字段作为第一响应者。我创建了一个图像用作否定按钮,该按钮将作为数字键盘的补充。

我想知道是否有办法检查数字键盘正在输入哪个文本字段。

如有任何帮助,我们将不胜感激!

最佳答案

如果所有潜在的第一响应者都是 UITextField,另一种方法是使 Controller 类符合 UITextFieldDelegate 协议(protocol),然后在开始编辑时获取对当前正在编辑的 UITextView 的引用。 使您的类符合您的 .h:

MyController : NSObject <UITextFieldDelegate>  //Might often be a UIViewController rather than an NSObject subclass...

定义属性:

@property (weak, nonatomic) UITextField *editingField;

然后在你的.m中综合:

@synthesize editingField = __editingField

然后实现:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    [self setEditingField:textField];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [self setEditingField:nil];
}

现在,每当您想知道哪个文本字段是您的第一响应者时:

UITextField *firstResponder = [self editingField];

关于ios - 检查当前响应者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10020931/

相关文章:

ios - 我可以获得有关 iOS 崩溃日志的帮助吗?

ios - 单点触控 : How to add a two finger gesture recognizer to UIPageViewController?

iphone - 在 iPhone 通讯录中创建群组

swift - 当tableView滚动到最高点时更新它?

C++:出现奇怪的 header 错误

ios - [NSDateFormatter 类] : message sent to deallocated instance

ios - 父级 UIViewControllers 是否应该将 didRotateFromInterfaceOrientation 传播给子级?

iphone - 查看 float 在所有 ViewControllers 之上

iphone - 如何在 iOS 中通过 3G 连接创建无线热点

iphone - 核心数据: fetch an NSManagedObject by its properties