我将尝试将ViewController中的数据传递给自定义的UITableViewCell,但是它没有生效。当我从ViewController.swift打印data时,一切都正常,但是当我从CustomCell.swift打印data时,数组为空。这是我的代码:
ViewController.swift
ViewController.swift
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as! CustomCell
cell.data = data[indexPath.row]
return cell
}
CustomCell.swift
class CustomCell: UITableViewCell {
var data = [CKRecord]()
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
println(data)
}
}