如何在Swift中创建一个UILabel数组

时间:2014-12-15 12:52:10

标签: ios swift uikit

如何在Swift中创建UILabel数组。当我尝试时,我收到类似ViewController.Type'dose not have a member named 'Lable00'的错误 我的代码:

import UIKit

class ViewController: UIViewController {

    let individualScores = [75, 43, 103, 87, 12]

    @IBOutlet var Lable00: UILabel?
    @IBOutlet var Lable01: UILabel?
    @IBOutlet var Lable02: UILabel?
    @IBOutlet var Lable03: UILabel?
    @IBOutlet var Lable04: UILabel?

    var Lable_Arr = [Lable00, Lable01, Lable02, Lable03, Lable04]

    override func viewDidLoad() {
        super.viewDidLoad()

        for score in individualScores {
        }
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

3 个答案:

答案 0 :(得分:4)

private var labels:[UILabel]()

override func viewDidLoad() 
{
    super.viewDidLoad()
    labels.append(Lable00)
    labels.append(Lable01)
    labels.append(Lable02)
    labels.append(Lable03)
    labels.append(Lable04)

    // do stuff with the labels view
}

答案 1 :(得分:3)

对于Swift 2

var labels:[UILabel]=[]

答案 2 :(得分:2)

在ViewDid加载中你不必附加,你可以像这样给标签分配一个新数组:

{{1}}