Xcode 6在IB中添加tableHeaderView

时间:2014-10-21 06:29:36

标签: ios uitableview xcode6

在Xcode 5中,我能够将UIView拖入IB中的UITableView以创建标题。然而在Xcode 6中,IB不会让我放弃一个。有没有办法再在IB中创建表头?

4 个答案:

答案 0 :(得分:35)

您只需将UIView拖到表格顶部(“原型单元格”文本上方)并将其保持在那里。下降指示器变为单个水平线,两端各有一个小圆圈。当你放弃它时,它会形成一个标题。

你可以在底部做类似的做一个页脚。

对于故事板中的表视图控制器:

enter image description here

对于xib中的表视图:

enter image description here

答案 1 :(得分:5)

右键单击XIB文件并选择“打开为”,选择源代码

查找tableview XML Element并替换为以下

  <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" style="plain" separatorStyle="none" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="YCz-1P-cVv">
                <rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
                <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                <view key="tableHeaderView" contentMode="scaleToFill" id="vv3-pk-N2N">
                    <rect key="frame" x="0.0" y="0.0" width="320" height="156"/>
                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                    <subviews>
                        <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="yho-bJ-IzF">
                            <rect key="frame" x="0.0" y="25" width="320" height="44"/>
                            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                        </imageView>
                    </subviews>
                    <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
                </view>
            </tableView>

使用Interface Builder XIB Document保存并打开XIB。

答案 2 :(得分:2)

我认为您应该按源代码添加表格页眉和页脚视图。 首先右键单击IB并打开源代码,然后放在代码

下面
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="none" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="MZF-la-Fpw">
                <rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
                <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                <view key="tableHeaderView" contentMode="scaleToFill" id="IDM-OR-d2g">
                    <rect key="frame" x="0.0" y="0.0" width="320" height="40"/>
                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                    <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                </view>
                <view key="tableFooterView" contentMode="scaleToFill" id="Q4z-o4-2rB">
                    <rect key="frame" x="0.0" y="518" width="320" height="50"/>
                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                    <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                </view>
                <connections>
                    <outlet property="dataSource" destination="-1" id="guW-ch-dgt"/>
                    <outlet property="delegate" destination="-1" id="j1u-5q-dsq"/>
                </connections>
            </tableView>

答案 3 :(得分:-1)

我最终做的(效果很好)是复制已经存在的UITableView,其中包含我之前使用Xcode 5设置的另一个NIB的标题。然后我只删除该表中的所有其他内容,除了标题只是这样我才能正确设置它。但是,只有在您之前使用Xcode 5中的Header设置表时,此技巧才有效。如果您正在使用新的Xcode 6项目,我仍然没有解决方案。

相关问题