Swift,Xib变量将数据传递给变量

时间:2015-04-28 20:08:08

标签: ios swift xib nib

我似乎无法按照我想要的方式完成这项工作。

我创建了一个xib文件,从中我选择一个表格单元格。我想在将单元格返回到TableView之前添加一些我修改过的变量。

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell:MakeMeTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("t5Cell") as! MakeMeTableViewCell
        cell.questionNumberLabel.text = "\(indexPath.row + 1)."
        cell.customVariable = "\(indexPath.row + 1)."
        return cell
    }

swift for xib

import UIKit

class Take5TableViewCell: UITableViewCell {
    @IBOutlet weak var questionNumberLabel: UILabel!

    var customVariable = ""

    override func awakeFromNib() {
        super.awakeFromNib()
        println("label: \(questionNumberLabel.text)")
        println("variable: \(customVariable)")
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }



}

我得到的输出是:

label: Optional("1.")
variable: 
label: Optional("1.")
variable: 
label: Optional("1.")
variable: 
label: Optional("1.")
variable: 
label: Optional("1.")
variable: 

我希望的输出是标签:1..2..3,变量:1..2..3

0 个答案:

没有答案