如何以编程方式获取UIVIewController的IBOutlet列表
问题描述:
我正在构建一个框架。我需要通过代码从UIViewcontroller获取IBOutels列表。我写了InterfaceOutletsReadable
协议。如果框架用户符合这个协议,我必须从ViewController读取IBOutlets列表。如何以编程方式获取UIVIewController的IBOutlet列表
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中收藏列表中。有没有办法以编程方式获得所有网点?
答
你可以拿IBOutletCollection
一个textField
并连接到所有others.It维护数组插座,你可以通过索引访问。
答
@IBOutlets
仅在设计时存在,即使在编译时也没有。因此,以所需方式获得所有网点是不可能的。出口与其他变量没有区别。
如果您需要在您的HomeViewController
和return Array
中实施readOutlets()
的网点列表包含您想要的任何变量。
那么问题是什么? –
@dahiya_boy它是一个框架项目。我必须从ViewController获取插座的列表。不通过IBOutlet集合。如何获得? –