UITextField 问题 - 输入附件和枚举

发布于 2024-11-25 06:20:46 字数 453 浏览 1 评论 0原文

在我的应用程序中,我有许多不同的功能。这些视图控制器都是我的自定义类 Function 的子类。通过子类化函数,它们继承了标准的东西,例如背景图像或适当的导航按钮。

我的问题是,我可以在函数的 viewDidLoad 中放入一些代码吗?这将使它能够在任何子类化它的控制器中为 UITextFields 设置参数。那么基本上是否可以获取某个类(在本例中为 UITextField)的类的所有属性?

我打算对此做的事情(除了标准化键盘、设置委托等),是创建一个带有上一个和下一个按钮的 UIToolbar,它会自动带您在文本字段之间切换(无需为每个功能编写代码) 。我知道您可以通过 iOS 模拟器中的文本字段进行枚举(通过按 Tab 键),但这是操作系统范围内的事情吗?

另外,如果您可以通过文本字段进行枚举,我可以制作一个应用程序范围的 hideKeyboard 方法和许多其他有用的东西...

提前致谢,我将不胜感激任何建议。

In my app, I have many different functions. These are view controllers that are all subclasses of my custom class, Function. By subclassing function, they inherit standard things like a background image, or the appropriate nav buttons.

My question is, can I put some code in function's viewDidLoad, that will enable it to set parameters for UITextFields in any controller that subclasses it. So basically is it possible to get all the properties of a class with a certain class (in this case UITextField)?

What I intend to do with this (apart from standardising the keyboards, setting the delegate etc.), is to create a UIToolbar with previous and next buttons on, which automatically takes you between text fields (without having to code it for each function). I know you can enumerate through text fields in the iOS simulator (by pressing tab), but is this an OS-wide thing?

Also if you could enumerate through text fields, I could make an app-wide hideKeyboard method and lots of other useful things...

Thanks in advance, I would appreciate any advice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔嚣张 2024-12-02 06:20:46

您想要在超类中实现 UITextFieldDelegate。每个子类应该负责创建文本字段的列表(NSArray)。一旦你有了这个,你就可以判断是否要离开“最后一个”文本字段,然后转到下一个控制器。

如果您想“tab”到下一个字段,您可以标记它们(或将它们保留在列表中)并使用委托方法和 becomeFirstResponder 来更改“关键字段”。

You want to implement the UITextFieldDelegate in your superclass. Each subclass should be responsible for creating a list (NSArray) of the text fields. Once you have that, you can tell if you are leaving the "last" text field, and go to the next controller.

If you want to "tab" to the next field, you can tag them (or keep them in a list) and use the delegate methods and becomeFirstResponder to change the "key field".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文