2
我创建了一个具有@IBOutlet
属性'label'的自定义UITableViewCell
子类,但是当我在viewDidLoad
函数中访问它时它是零。Swift:无法在自定义UITableViewCell中访问IBOutlet
TableViewController.swift
import UIKit
class TableViewController: UITableViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
var cell = TableViewCell(style:UITableViewCellStyle.Default, reuseIdentifier:nil)
println(cell.label) // nil
}
}
TableViewCell.swift
import UIKit
class TableViewCell:UITableViewCell
{
@IBOutlet weak var label: UILabel!
}
Main.storyboard
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="TableViewCell" id="cNV-ZQ-ovR" customClass="TableViewCell" customModule="SimpleTable" customModuleProvider="target">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="cNV-ZQ-ovR" id="3Qh-aQ-Ys2">
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="H9h-90-Iff">
<rect key="frame" x="15" y="12" width="252" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="label" destination="H9h-90-Iff" id="tMj-pZ-Ad2"/>
</connections>
</tableViewCell>
的Xcode 6.1 build6A1052d