Can't hook up an outlet collection in Xcode 6 using storyboard

后端 未结 4 715
北荒
北荒 2020-12-10 17:03

I am having trouble creating an outlet collection in Xcode 6. Outlet collections in Xcode 6 now function as regular IBOutlets, and you use the same @IBOutlet attribute to de

4条回答
  •  误落风尘
    2020-12-10 17:22

    You've got it right, you just need to define the array more formally:

    @IBOutlet var cardButtons: Array
    

    Now you'll be able to connect the buttons from IB.


    The above should work, but still doesn't in Xcode 6 beta 3. A workaround is to use an NSArray until Xcode and Swift can handle this properly:

    class ViewController: UIViewController {
        @IBOutlet strong var labels: NSArray!
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            for label in self.labels as [UILabel] {
                label.textColor = UIColor.redColor()
            }
        }
    }
    

提交回复
热议问题