减少奥特莱斯数量? Swift
Reduce number of Outlets? Swift
我已经开始学习 Swift 并从一些简单的游戏开始。但是每次(取决于游戏)我的代码都是这样的:
@IBOutlet weak var B1: UIButton!
@IBOutlet weak var B2: UIButton!
@IBOutlet weak var B3: UIButton!
@IBOutlet weak var B4: UIButton!
@IBOutlet weak var B5: UIButton!
@IBOutlet weak var B6: UIButton!
@IBOutlet weak var B7: UIButton!
@IBOutlet weak var B8: UIButton!
@IBOutlet weak var B9: UIButton!
@IBOutlet weak var B10: UIButton!
@IBOutlet weak var B11: UIButton!
@IBOutlet weak var B12: UIButton!
@IBOutlet weak var B13: UIButton!
@IBOutlet weak var B14: UIButton!
@IBOutlet weak var B15: UIButton!
@IBOutlet weak var B16: UIButton!
@IBOutlet weak var B17: UIButton!
@IBOutlet weak var B18: UIButton!
@IBOutlet weak var B19: UIButton!
@IBOutlet weak var B20: UIButton!
@IBOutlet weak var B21: UIButton!
@IBOutlet weak var B22: UIButton!
@IBOutlet weak var B23: UIButton!
@IBOutlet weak var B24: UIButton!
@IBOutlet weak var B25: UIButton!
@IBOutlet weak var B26: UIButton!
@IBOutlet weak var B27: UIButton!
@IBOutlet weak var B28: UIButton!
@IBOutlet weak var B29: UIButton!
@IBOutlet weak var B30: UIButton!
@IBOutlet weak var B31: UIButton!
@IBOutlet weak var B32: UIButton!
@IBOutlet weak var L1: UILabel!
@IBOutlet weak var L2: UILabel!
@IBOutlet weak var L3: UILabel!
@IBOutlet weak var L4: UILabel!
@IBOutlet weak var L5: UILabel!
@IBOutlet weak var L6: UILabel!
@IBOutlet weak var L7: UILabel!
@IBOutlet weak var L8: UILabel!
@IBOutlet weak var L9: UILabel!
@IBOutlet weak var L10: UILabel!
@IBOutlet weak var L11: UILabel!
@IBOutlet weak var L12: UILabel!
@IBOutlet weak var L13: UILabel!
@IBOutlet weak var L14: UILabel!
@IBOutlet weak var L15: UILabel!
@IBOutlet weak var L16: UILabel!
@IBOutlet weak var L17: UILabel!
@IBOutlet weak var L18: UILabel!
@IBOutlet weak var L19: UILabel!
@IBOutlet weak var L20: UILabel!
@IBOutlet weak var L21: UILabel!
@IBOutlet weak var L22: UILabel!
@IBOutlet weak var L23: UILabel!
@IBOutlet weak var L24: UILabel!
@IBOutlet weak var L25: UILabel!
@IBOutlet weak var L26: UILabel!
@IBOutlet weak var L27: UILabel!
@IBOutlet weak var L28: UILabel!
@IBOutlet weak var L29: UILabel!
@IBOutlet weak var L30: UILabel!
@IBOutlet weak var L31: UILabel!
@IBOutlet weak var L32: UILabel!
@IBOutlet weak var C1: UIButton!
@IBOutlet weak var C2: UIButton!
@IBOutlet weak var C3: UIButton!
@IBOutlet weak var C4: UIButton!
@IBOutlet weak var C5: UIButton!
@IBOutlet weak var C6: UIButton!
@IBOutlet weak var C7: UIButton!
@IBOutlet weak var C8: UIButton!
@IBOutlet weak var randomPin1: UIButton!
@IBOutlet weak var randomPin2: UIButton!
@IBOutlet weak var randomPin3: UIButton!
@IBOutlet weak var randomPin4: UIButton!
我对此很不满意,有没有办法在不创建 '@IBOutlet weak var name 的情况下使用这些按钮(或任何类型):类型!'?就像使用标识符然后使用标识符访问 Button 一样?或者这只是执行此操作的常规方法?提前致谢!
您应该使用 IB Outlet Collections 并将这些实例存储在数组中:
http://nshipster.com/ibaction-iboutlet-iboutletcollection/
https://medium.com/@abhimuralidharan/what-is-an-iboutletcollection-in-ios-78cfbc4080a1
我已经开始学习 Swift 并从一些简单的游戏开始。但是每次(取决于游戏)我的代码都是这样的:
@IBOutlet weak var B1: UIButton!
@IBOutlet weak var B2: UIButton!
@IBOutlet weak var B3: UIButton!
@IBOutlet weak var B4: UIButton!
@IBOutlet weak var B5: UIButton!
@IBOutlet weak var B6: UIButton!
@IBOutlet weak var B7: UIButton!
@IBOutlet weak var B8: UIButton!
@IBOutlet weak var B9: UIButton!
@IBOutlet weak var B10: UIButton!
@IBOutlet weak var B11: UIButton!
@IBOutlet weak var B12: UIButton!
@IBOutlet weak var B13: UIButton!
@IBOutlet weak var B14: UIButton!
@IBOutlet weak var B15: UIButton!
@IBOutlet weak var B16: UIButton!
@IBOutlet weak var B17: UIButton!
@IBOutlet weak var B18: UIButton!
@IBOutlet weak var B19: UIButton!
@IBOutlet weak var B20: UIButton!
@IBOutlet weak var B21: UIButton!
@IBOutlet weak var B22: UIButton!
@IBOutlet weak var B23: UIButton!
@IBOutlet weak var B24: UIButton!
@IBOutlet weak var B25: UIButton!
@IBOutlet weak var B26: UIButton!
@IBOutlet weak var B27: UIButton!
@IBOutlet weak var B28: UIButton!
@IBOutlet weak var B29: UIButton!
@IBOutlet weak var B30: UIButton!
@IBOutlet weak var B31: UIButton!
@IBOutlet weak var B32: UIButton!
@IBOutlet weak var L1: UILabel!
@IBOutlet weak var L2: UILabel!
@IBOutlet weak var L3: UILabel!
@IBOutlet weak var L4: UILabel!
@IBOutlet weak var L5: UILabel!
@IBOutlet weak var L6: UILabel!
@IBOutlet weak var L7: UILabel!
@IBOutlet weak var L8: UILabel!
@IBOutlet weak var L9: UILabel!
@IBOutlet weak var L10: UILabel!
@IBOutlet weak var L11: UILabel!
@IBOutlet weak var L12: UILabel!
@IBOutlet weak var L13: UILabel!
@IBOutlet weak var L14: UILabel!
@IBOutlet weak var L15: UILabel!
@IBOutlet weak var L16: UILabel!
@IBOutlet weak var L17: UILabel!
@IBOutlet weak var L18: UILabel!
@IBOutlet weak var L19: UILabel!
@IBOutlet weak var L20: UILabel!
@IBOutlet weak var L21: UILabel!
@IBOutlet weak var L22: UILabel!
@IBOutlet weak var L23: UILabel!
@IBOutlet weak var L24: UILabel!
@IBOutlet weak var L25: UILabel!
@IBOutlet weak var L26: UILabel!
@IBOutlet weak var L27: UILabel!
@IBOutlet weak var L28: UILabel!
@IBOutlet weak var L29: UILabel!
@IBOutlet weak var L30: UILabel!
@IBOutlet weak var L31: UILabel!
@IBOutlet weak var L32: UILabel!
@IBOutlet weak var C1: UIButton!
@IBOutlet weak var C2: UIButton!
@IBOutlet weak var C3: UIButton!
@IBOutlet weak var C4: UIButton!
@IBOutlet weak var C5: UIButton!
@IBOutlet weak var C6: UIButton!
@IBOutlet weak var C7: UIButton!
@IBOutlet weak var C8: UIButton!
@IBOutlet weak var randomPin1: UIButton!
@IBOutlet weak var randomPin2: UIButton!
@IBOutlet weak var randomPin3: UIButton!
@IBOutlet weak var randomPin4: UIButton!
我对此很不满意,有没有办法在不创建 '@IBOutlet weak var name 的情况下使用这些按钮(或任何类型):类型!'?就像使用标识符然后使用标识符访问 Button 一样?或者这只是执行此操作的常规方法?提前致谢!
您应该使用 IB Outlet Collections 并将这些实例存储在数组中:
http://nshipster.com/ibaction-iboutlet-iboutletcollection/ https://medium.com/@abhimuralidharan/what-is-an-iboutletcollection-in-ios-78cfbc4080a1