我有一些IBOutlets:
@IBOutlet weak var r1c1: MyLabel!
@IBOutlet weak var r1c2: MyLabel!
@IBOutlet weak var r2c1: MyLabel!
@IBOutlet weak var r2c2: MyLabel!
我想把它们放在一个二维数组中:
var grid: [[MyLabel]] = [[r1c1,r1c2],[r2c1,r2c2]]
但是当我编译时,Xcode会出现以下错误:
InterfaceController.type does not have a member named 'r1c1'
有什么问题?
答案 0 :(得分:0)
我认为您的代码很好,但您必须将您的数组放在本地范围内:
func printFirst() {
var grid: [[MyLabel]] = [[r1c1,r1c2],[r2c1,r2c2]]
println(grid[0][0]).text // or stringValue
}
更新
@IBOutlet weak var r1c1: MyLabel!
@IBOutlet weak var r1c2: MyLabel!
@IBOutlet weak var r2c1: MyLabel!
@IBOutlet weak var r2c2: MyLabel!
var grid = [[MyLabel]]()
override func viewDidLoad() {
super.viewDidLoad()
grid = [[r1c1,r1c2],[r2c1,r2c2]]
}