ios - 如何以编程方式获取 UIVIewController 的 IBOutlet 列表

标签 ios swift uiviewcontroller interface-builder

我正在构建一个框架。我需要通过代码从 UIViewcontroller 获取 IBOutels 列表。我已经编写了 InterfaceOutletsReadable 协议(protocol)。如果框架用户遵守此协议(protocol),我必须从 ViewController 读取 IBOutlets 列表。

 protocol InterfaceOutletsReadable {
     ///Read the outlets objects
     func readOutlets()
 }
 extension InterfaceOutletsReadable {
    //TODO:- Stuck at this stage. Here I have to read the viewcontroller IBOutlets
 }
 class HomeViewController: InterfaceOutletsReadable {
     @IBOutlet weak var userNameTextField: UITextField!
     @IBOutlet weak var passwordTextField: UITextField!
     @IBOutlet weak var errorLabel: UILabel!
 }

编辑:我不想从 IBOutlet Collection 中获取列表。有没有办法以编程方式获取所有网点?

最佳答案

你可以获取一个 textFieldIBOutletCollection 并连接到所有其他的。它维护了一个 Outlet 数组,你可以通过索引访问。

关于ios - 如何以编程方式获取 UIVIewController 的 IBOutlet 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43534478/

相关文章:

SwiftUI - TabView 内的 OnExitCommand

swift - 如何用字典填充选择器 View ?

iphone - iOS4如何重启 View Controller

iphone - 当内容适合屏幕时,如何在 UITableView 中禁用滚动?

objective-c - UIBarButtonItem 图像(或 UIToolbar 自定义背景图像?..)比原始图像更暗(或更亮?..)

ios - 在 iOS 7 上压缩的 UITableView sectionIndexTitles

ios - 将 UIView 设置为键盘高度

ios - 闪屏未显示钛加速器 5.2.2GA

ios - 在swift中将参数数组作为请求主体传递

ios - 将值传递给 UIView 返回 nil