无法使用故事板在 Xcode 6 中连接插座集合 [英] Can't hook up an outlet collection in Xcode 6 using storyboard

查看:36
本文介绍了无法使用故事板在 Xcode 6 中连接插座集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xcode 6 中创建插座集合时遇到问题.Xcode 6 中的插座集合现在用作常规 IBOutlets,并且您使用相同的 @IBOutlet 属性来声明插座集合,同时确保为该类型指定一个数组.我已经在我的视图控制器的 swift 文件中做到了这一点,即

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 declare an outlet collection while being sure to specify an array for the type. I have done this in my view controller's swift file i.e.

@IBOutlet var cardButtons: UIButton[]

在 Xcode 5 中,当一个控件使用助手编辑器从故事板中的元素拖动到相应的视图控制器时,它们会看到一个选项来创建插座或插座集合.这在 Xcode 6 中似乎不再可能,我的猜测是因为 outlet 和 outlet 集合现在共享相同的 @IBOutlet 属性.我应该如何创建一个包含 10 个按钮的插座集合,而无法控制从故事板视图中拖动每个按钮并将其连接到我的

In Xcode 5 when one control drags from an element in the storyboard to the corresponding view controller using the assistant editor they are presented with an option to create either an outlet or an outlet collection. This seems to no longer be possible in Xcode 6 and my guess is because outlets and outlet collection now share the same @IBOutlet attribute. How should I create an outlet collection which will contain say 10 buttons without being able to control drag each one from the storyboard view and hook it up to my

@IBOutlet var cardButtons: UIButton[] 

我的视图控制器 swift 文件中的属性?

property in my view controller swift file?

推荐答案

你说得对,你只需要更正式地定义数组:

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

@IBOutlet var cardButtons: Array<UIButton>

现在您可以连接来自 IB 的按钮.

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

上述应该可以工作,但在 Xcode 6 beta 3 中仍然不行.解决方法是使用 NSArray 直到 Xcode 和 Swift 可以正确处理:

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()
        }
    }
}

这篇关于无法使用故事板在 Xcode 6 中连接插座集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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