Reputation: 4986
I somehow created a UITableViewController in storyboards with static cells and was able to add a UINavigationBar on top of the UITableView. I am now trying to work with the new iOS7 status bar offset and was trying to see which view is inside of which and thats when I noticed this:
Ive been trying to recreate this but it has been impossible. XCode will not let me add a UINavbar on top of or before a UITableView Section. Instead it always does this:
where the navbar is even outside the tableview.
Any ideas why?
Upvotes: 0
Views: 2205
Reputation: 39512
EDIT
I was just able to drop a UINavigationBar in the table header view of a UITableView in a UITableViewController in a storyboard in Xcode 5. The trick is top drop it on the very very top of the UITableView. To make it easier you can configure the simulated metrics to show a top navigation bar and drop the navigation bar component on top of that. It drops right into place.
Re. the additional question in the comment about pushing it down 20px. There's no automatic way unless you are using an actual UINavigationController. Manually you can set the tableview content insets to have 20 points specified for the top margin.
Original
It looks as if you were able to add the UINavigationBar
as the table-header-view. I wasn't able to do this via IB, but I was able to add a navbar as the table-footer-view. Then I went into the xml source and changed the "key" property of the navigationBar
element from "tableFooterView
" to "tableHeaderView
". Opening it back up in IB made the layout just like yours.
An alternate way to get a UINavigationBar in the table header view via IB is to drag a UIView in there and change the class type. But this won't change the IB windows - to IB it will just be a UIView.
Here's the storyboard XML post modification:
<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>
Upvotes: 1
Reputation: 17556
I think the difference between the two is that the first one is a standard view controller. The second one is a tableview controller. In the standard drag out tableview controller, you cannot resize the tableview so that you have space to drag in a navigation bar.
If you drag out a standard view controller then drag out a tableview controller, you can resize the tableview so it doesn't fill the entire screen and you can add a navigation bar manually.
Xcode just doesn't like you adding a navigation bar to a tableview controller for some reason.
Upvotes: 0