2014-10-29 66 views
0

我正将旧应用程序从.xib-s迁移到.storyboard-s。这些.xib文件有很多IBOutlet连接,并且复制&粘贴视图并重新创建它们非常耗时。我想知道是否有办法做到这一点无缝。任何人都知道解决这个问题?从.xib复制到.storyboard并保留IBOutlet连接

+0

我认为只要您将ViewController类更改为您的实际控制器类,Xcode就会自动执行此操作。你不能做任何事情,但如果xcode不会自动完成的话。 – iphonic 2014-10-29 10:23:09

回答

0

是的,有一种方法。

  1. 确保故事板视图控制器场景具有为视图控制器设置的正确类。

  2. 右键单击xib文件,然后选择打开为 - >源代码。

  3. 找到<subviews> ... </subviews>对标签,并复制该部分。

  4. 以同样的方式打开故事板(打开为 - >源代码)并在xml中找到相应的视图控制器(用xml注释标记,例如<!--MyViewController>),然后从xib复制和粘贴xml子视图,里面的视图控制器<view> ... </view>标签。例如

    <viewController id="vXZ-lx-hvc" customClass="TwoViewController" sceneMemberID="viewController"> 
          <layoutGuides> 
           <viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/> 
           <viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/> 
          </layoutGuides> 
          <view key="view" contentMode="scaleToFill" id="kh9-bI-dsS"> 
           <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> 
           <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> 
           <subviews> 
            <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fLe-1C-hTu"> 
             <rect key="frame" x="116" y="244" width="46" height="30"/> 
             <state key="normal" title="Button"> 
              <color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/> 
             </state> 
            </button> 
           </subviews> 
           <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> 
          </view> 
         </viewController> 
    
  5. 重复与<connections> ... </connections>以上步骤,在所有IBOutlets复制。需要注意的是连接去<view> .. </view>标签的下面,但里面的<viewController> ... </viewController>

    <viewController id="vXZ-lx-hvc" customClass="TwoViewController" sceneMemberID="viewController"> 
           <layoutGuides> 
            <viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/> 
            <viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/> 
           </layoutGuides> 
           <view key="view" contentMode="scaleToFill" id="kh9-bI-dsS"> 
            <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> 
            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> 
            <subviews> 
             <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fLe-1C-hTu"> 
              <rect key="frame" x="116" y="244" width="46" height="30"/> 
              <state key="normal" title="Button"> 
               <color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/> 
              </state> 
              <connections> 
               <action selector="samButtonTap:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="1sQ-0S-S8z"/> 
              </connections> 
             </button> 
            </subviews> 
            <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> 
           </view> 
           <connections> 
            <outlet property="samButton" destination="fLe-1C-hTu" id="8GK-Nn-Loy"/> 
           </connections> 
          </viewController> 
    

你会从第二片断IBActions与观点,其中作为IBOutlets中表示在一起后子视图有代表注意到已被宣布。

根据xib文件的复杂程度,您可能需要做更多的工作。如果您决定重新创建一些xib组件,而不是将它们复制到ID中,则会发生更改,因此请注意这一点。一旦完成,不要忘记从项目中删除你的xib文件。

+1

我想过这个,但希望有另一种方式。现在谁想要编写一个能够自动完成的应用:) – 2015-03-06 14:25:35