我如何设法在UITableView部分上方的故事板中添加UINavigationBar?

时间:2013-09-20 22:15:40

标签: ios xcode uitabbarcontroller uinavigationbar

我以某种方式在带有静态单元格的故事板中创建了一个UITableViewController,并且能够在UITableView的顶部添加UINavigationBar。我现在正在尝试使用新的iOS7状态栏偏移量,并且当我注意到这一点时,我正试图查看哪个视图在哪个内部,那就是:

enter image description here

我一直试图重新创造这个,但这是不可能的。 XCode不允许我在UITableView部分之上或之前添加UINavbar。相反,它始终这样做:

enter image description here

导航栏甚至在桌面视图之外。

任何想法为什么?

2 个答案:

答案 0 :(得分:1)

修改

我只能在Xcode 5的故事板中的UITableViewController中的UITableView的表头视图中删除UINavigationBar。诀窍是将它放在UITableView的最顶端。为了方便起见,您可以配置模拟指标以显示顶部导航栏并将导航栏组件放在其上。它落到了原地。

重新。关于将其压低20px的评论中的其他问题。除非您使用的是实际的UINavigationController,否则没有自动方式。您可以手动设置tableview内容插入,为上边距指定20个点。

<强>原始

看起来您可以将UINavigationBar添加为table-header-view。我无法通过IB做到这一点,但我能够添加一个导航栏作为表 - 页脚 - 视图。然后我进入xml源并将navigationBar元素的“key”属性从“tableFooterView”更改为“tableHeaderView”。在IB中打开它使得布局就像你的一样。

通过IB在表头视图中获取UINavigationBar的另一种方法是在其中拖动UIView并更改类类型。但这不会改变IB窗口 - 对IB来说它只是一个UIView。

这是故事板XML后期修改:

<scene sceneID="AAh-fX-ffB">
            <objects>
                <tableViewController id="aWk-nr-T8Z" sceneMemberID="viewController">
                    <tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="UP8-s3-1Gh">
                        <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"/>
                        <navigationBar key="tableHeaderView" contentMode="scaleToFill" id="VMO-sB-hzN">
                            <rect key="frame" x="0.0" y="110" width="320" height="44"/>
                            <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
                            <items>
                                <navigationItem title="Title" id="cGh-ax-HpR"/>
                            </items>
                        </navigationBar>
                        <prototypes>
                            <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="XpO-wE-6cr">
                                <rect key="frame" x="0.0" y="66" width="320" height="44"/>
                                <autoresizingMask key="autoresizingMask"/>
                                <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="XpO-wE-6cr" id="VKA-tU-Yjw">
                                    <rect key="frame" x="0.0" y="0.0" width="320" height="43"/>
                                    <autoresizingMask key="autoresizingMask"/>
                                </tableViewCellContentView>
                            </tableViewCell>
                        </prototypes>
                        <connections>
                            <outlet property="dataSource" destination="aWk-nr-T8Z" id="n7K-0q-ZI8"/>
                            <outlet property="delegate" destination="aWk-nr-T8Z" id="ZFM-QX-8D4"/>
                        </connections>
                    </tableView>
                </tableViewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="yCS-a8-E82" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="201" y="200"/>
        </scene>

答案 1 :(得分:0)

我认为两者之间的区别在于第一个是标准视图控制器。第二个是tableview控制器。在标准拖出tableview控制器中,您无法调整tableview的大小,以便在导航栏中有可以拖动的空间。

如果您拖出标准视图控制器然后拖出一个tableview控制器,您可以调整tableview的大小,使其不会填满整个屏幕,您可以手动添加导航栏。

Xcode不喜欢你出于某种原因向tableview控制器添加导航栏。