Swift将多个IBOutlet放在一个数组中 [英] Swift put multiple IBOutlets in an Array

查看:187
本文介绍了Swift将多个IBOutlet放在一个数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

红色边框)IBOutlets使用ctrl +拖动

但我不喜欢有完全相同的行9次(DRY)

我如何把这些IBOutlets在数组? / p>

I made these (marked with red border) IBOutlets using ctrl + drag
But i don't like to have the exact same line 9 times (DRY)
How do i put these IBOutlets in an Array?

推荐答案

您可以在 Swift 中定义通用出口集合:

you can define a generic outlet collection in Swift like this:

@IBOutlet var collectionOfViews: Array<UIView>?

UIButton objects:

@IBOutlet var collectionOfButtons: Array<UIButton>?






在连接5个随机按钮后,我会在我的控制台上看到:

it would look on my console after connecting 5 random buttons:

这篇关于Swift将多个IBOutlet放在一个数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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