【发布时间】:2020-06-22 19:36:47
【问题描述】:
我试图将 9 个按钮放入一个数组中,但出现错误
不能在属性初始化器中使用实例成员“oneOne”;属性初始化器在“self”可用之前运行
每个按钮 9 次,这是我的代码。非常感谢任何帮助,我是 iOS 开发的新手。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBOutlet var oneOne: UIButton!
@IBOutlet var twoOne: UIButton!
@IBOutlet var threeOne: UIButton!
@IBOutlet var oneTwo: UIButton!
@IBOutlet var twoTwo: UIButton!
@IBOutlet var threeTwo: UIButton!
@IBOutlet var oneThree: UIButton!
@IBOutlet var twoThree: UIButton!
@IBOutlet var threeThree: UIButton!
var allSpaces = [oneOne,twoOne,threeOne,oneTwo,twoTwo,threeTwo,oneThree,twoThree,threeThree]
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
谢谢
【问题讨论】:
-
或者,使用 IB 将这些按钮添加到 Outlet Collection。
-
行前添加
lazy
标签: ios arrays swift xcode iboutlet