iOS Swift

Convert a UITableviewController to a UIViewController


If you add a new Navigation Controller to an IOS Swift project you will find it adds a new TableViewController. But what if you want a UIViewController instead?

There is no good way through interface builder to convert a UITableviewController to a UIViewController so you will have to dive into the XML source code that is your storyboard to switch it out. Don’t worry its not hard.

This code is from Xcode 6.1.1, leave comments if you have other version issues.

In the file manager, right click on your storyboard,  and select Open As > Source Code

Search for the name of the new view you have added, in this case, “sync results”

<!--SYNC RESULTS-->
 <scene sceneID="C5M-Yf-7Ry">
  <objects>
    <tableViewController id="FNU-bQ-UdX" sceneMemberID="viewController">
     <navigationItem key="navigationItem" title="SYNC RESULTS" id="Fjg-OD-J0R"/>
    </tableViewController>
    <placeholder placeholderIdentifier="IBFirstResponder" id="WYv-8v-0iC" userLabel="First Responder" sceneMemberID="firstResponder"/>
  </objects>
  <point key="canvasLocation" x="7462" y="4961"/>
 </scene>

Then remove the red text above and paste just the blue text below:

<!--SYNC RESULTS-->
<scene sceneID="UuP-JX-s8X">
  <objects>
    <viewController title="FIXME" sceneMemberID="viewController">
      <layoutGuides>
        <viewControllerLayoutGuide type="top"/>
        <viewControllerLayoutGuide type="bottom"/>
      </layoutGuides>
      <view key="view" contentMode="scaleToFill">
        <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
        <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
      </view>
    </viewController>
    <placeholder placeholderIdentifier="IBFirstResponder" id="tbi-cJ-Rrv" userLabel="First Responder" sceneMemberID="firstResponder"/>
  </objects>
  <point key="canvasLocation" x="519" y="-118"/>
</scene>

Right click on the storyboard and switch it back to Interface Builder. You will get a minor warning that IB will fix up your storyboard because I have removed all ID fields above. It will then autogenerate new ones and have no issue (hopefully).

openanalytics 3825 views

I'm a 35 year old UIUC Computer Engineer building mobile apps, websites and hardware integrations with an interest in 3D printing, biotechnology and Arduinos.


View Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.