Swift,Xcode 6 beta 4:在IB中创建的静态UITableView的单元格显示为空白

时间:2014-07-29 12:16:29

标签: xcode uitableview swift beta

我在静态UITableView的表视图单元格中有一些文本字段。一切都在IB内部创建的故事板中。

enter image description here

当我在iOS模拟器中构建并运行应用程序时,文本字段已消失。

enter image description here

我正在从Objective C应用程序转换代码,并且我已将组件的UI属性设置为与Objective C故事板中的相同。

自动布局类和约束都无法解决问题。

这是Xcode Beta的错误还是我做错了什么?

P.S。这是这个控制器()的stoyboard代码:

        <!--New Deck-->
    <scene sceneID="O9s-gL-vM7">
        <objects>
            <tableViewController id="vxV-hN-f9Q" customClass="NewDeckTVC" customModule="SwiftPhotoCards" customModuleProvider="target" sceneMemberID="viewController">
                <tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" allowsSelection="NO" showsSelectionImmediatelyOnTouchBegin="NO" rowHeight="44" sectionHeaderHeight="10" sectionFooterHeight="10" id="oks-XI-V2i">
                    <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                    <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
                    <sections>
                        <tableViewSection headerTitle="Properties" id="WvN-Eh-a9P">
                            <cells>
                                <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="0.0" shouldIndentWhileEditing="NO" id="1tw-Nd-mn9">
                                    <autoresizingMask key="autoresizingMask"/>
                                    <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="1tw-Nd-mn9" id="EUh-76-F0U">
                                        <autoresizingMask key="autoresizingMask"/>
                                        <subviews>
                                            <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="prototype" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="g4z-60-BpB">
                                                <rect key="frame" x="0.0" y="-30" width="97" height="30"/>
                                                <color key="backgroundColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
                                                <fontDescription key="fontDescription" type="system" pointSize="14"/>
                                                <textInputTraits key="textInputTraits" returnKeyType="done"/>
                                                <variation key="widthClass=compact" fixedFrame="YES">
                                                    <rect key="frame" x="20" y="7" width="360" height="30"/>
                                                </variation>
                                            </textField>
                                        </subviews>
                                        <variation key="default">
                                            <mask key="subviews">
                                                <exclude reference="g4z-60-BpB"/>
                                            </mask>
                                        </variation>
                                        <variation key="widthClass=compact">
                                            <mask key="subviews">
                                                <include reference="g4z-60-BpB"/>
                                            </mask>
                                        </variation>
                                    </tableViewCellContentView>
                                </tableViewCell>
                                <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="BLc-t3-nmw">
                                    <autoresizingMask key="autoresizingMask"/>
                                    <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="BLc-t3-nmw" id="R22-JQ-5ze">
                                        <autoresizingMask key="autoresizingMask"/>
                                        <subviews>
                                            <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="title" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="V91-KT-VGf">
                                                <rect key="frame" x="0.0" y="-30" width="97" height="30"/>
                                                <color key="backgroundColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
                                                <fontDescription key="fontDescription" type="system" pointSize="14"/>
                                                <textInputTraits key="textInputTraits"/>
                                                <variation key="widthClass=compact" fixedFrame="YES">
                                                    <rect key="frame" x="20" y="7" width="360" height="30"/>
                                                </variation>
                                            </textField>
                                        </subviews>
                                        <variation key="default">
                                            <mask key="subviews">
                                                <exclude reference="V91-KT-VGf"/>
                                            </mask>
                                        </variation>
                                        <variation key="widthClass=compact">
                                            <mask key="subviews">
                                                <include reference="V91-KT-VGf"/>
                                            </mask>
                                        </variation>
                                    </tableViewCellContentView>
                                </tableViewCell>
                            </cells>
                        </tableViewSection>
                        <tableViewSection headerTitle="Optional Details" id="E6X-rL-niX">
                            <cells>
                                <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="97" id="wYf-24-lTe">
                                    <autoresizingMask key="autoresizingMask"/>
                                    <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="wYf-24-lTe" id="bbg-bT-RMU">
                                        <autoresizingMask key="autoresizingMask"/>
                                        <subviews>
                                            <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="SvD-vf-INK">
                                                <rect key="frame" x="0.0" y="0.0" width="240" height="128"/>
                                                <color key="backgroundColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
                                                <fontDescription key="fontDescription" type="system" pointSize="14"/>
                                                <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
                                                <variation key="widthClass=compact" fixedFrame="YES">
                                                    <rect key="frame" x="20" y="21" width="360" height="56"/>
                                                </variation>
                                            </textView>
                                        </subviews>
                                        <variation key="default">
                                            <mask key="subviews">
                                                <exclude reference="SvD-vf-INK"/>
                                            </mask>
                                        </variation>
                                        <variation key="widthClass=compact">
                                            <mask key="subviews">
                                                <include reference="SvD-vf-INK"/>
                                            </mask>
                                        </variation>
                                    </tableViewCellContentView>
                                </tableViewCell>
                            </cells>
                        </tableViewSection>
                    </sections>
                    <connections>
                        <outlet property="dataSource" destination="vxV-hN-f9Q" id="jSB-sV-T8O"/>
                        <outlet property="delegate" destination="vxV-hN-f9Q" id="BIo-1e-3Bf"/>
                    </connections>
                </tableView>
                <navigationItem key="navigationItem" title="New Deck" id="SAt-ai-Zai">
                    <barButtonItem key="leftBarButtonItem" title="Cancel" id="GXX-Qh-k3l">
                        <connections>
                            <action selector="cancel:" destination="vxV-hN-f9Q" id="daP-To-eBY"/>
                        </connections>
                    </barButtonItem>
                    <barButtonItem key="rightBarButtonItem" title="Done" id="AyJ-ZJ-4mZ">
                        <connections>
                            <action selector="done:" destination="vxV-hN-f9Q" id="Mqh-ly-BT8"/>
                            <segue destination="AYl-ed-7OV" kind="unwind" identifier="return to decks" unwindAction="doneNewDeck:" id="1hN-3u-fRx"/>
                        </connections>
                    </barButtonItem>
                </navigationItem>
                <connections>
                    <outlet property="detailsView" destination="SvD-vf-INK" id="ozl-eB-fcA"/>
                    <outlet property="protoField" destination="g4z-60-BpB" id="vNM-kn-BQS"/>
                    <outlet property="titleField" destination="V91-KT-VGf" id="JHu-D2-cFA"/>
                </connections>
            </tableViewController>
            <placeholder placeholderIdentifier="IBFirstResponder" id="1p2-Jl-jy2" userLabel="First Responder" sceneMemberID="firstResponder"/>
            <exit id="AYl-ed-7OV" userLabel="Exit" sceneMemberID="exit"/>
        </objects>
        <point key="canvasLocation" x="2764.5" y="-80"/>
    </scene>

这里是UITableViewController子类(目前只是一个存根):

class NewDeckTVC: UITableViewController {
var protos:[String]!
var newDeckProps:[String:String]!

@IBOutlet weak var protoField: UITextField!
@IBOutlet weak var titleField: UITextField!
@IBOutlet weak var detailsView: UITextView!

@IBAction func cancel(sender: AnyObject) {
    presentingViewController.dismissViewControllerAnimated(true, completion: nil)
}

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if segue.identifier == "return to decks" {
        newDeckProps = ["proto":protoField.text, "title":titleField.text, "details":detailsView.text]
    }
}

}

1 个答案:

答案 0 :(得分:0)

将表视图的dataSource和委托连接到类并覆盖表视图的委托方法

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
    return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return noOfRows
}