Move or copy view controller from one storyboard to another

前端 未结 9 830
暖寄归人
暖寄归人 2021-01-30 19:46

I have several UIViewControllers in one Storyboard. Now I want to move some UIViewControllers to another Storyboard. Is it possible?

相关标签:
9条回答
  • 2021-01-30 19:56

    It´s possible to copy/paste but it only works if you have both Storyboards open side by side using Xcode´s Assistant Editor.

    0 讨论(0)
  • 2021-01-30 20:01

    Interface elements can be moved between Xib and Storyboard files via Copy / Paste.

    This was not originally working for me. I was attempting to copy a UICollectionViewCell from a dedicated Xib to our Main Storyboard. The cell would not copy into the Storyboard.

    The solution was to Select the specific parent element in the storyboard. The UICollectionViewCell can be pasted in as a child of a UICollectionView in the storyboard, but otherwise cannot be pasted.

    If you're having trouble pasting a specific item, be sure to double check that you have selected a valid parent element before attempting to paste.

    0 讨论(0)
  • 2021-01-30 20:04

    In Xcode 8, if specifically you want to move view controllers to another storyboard, just select the view controller(s) which you want to move by Cmd + click the view controller. Keeping them selected, Go to the Editor tab and Choose Refactor to Storyboard. It will ask you the name of the new storyboard file and press Enter.

    A new storyboard file will be created with your selected view controllers in it. In the Main.storyboard, you will see a Storyboard Reference object in place of that view controller, which is your reference to the new storyboard you just made.

    0 讨论(0)
  • 2021-01-30 20:04

    I think it is possible....

    UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"secondStoryBoard" bundle:nil];
    
    UIViewController *theTabBar = [secondStoryBoard instantiateViewControllerWithIdentifier:@"myTabBar"];
    
    [self.navigationController pushViewController:theTabBar animated:YES];
    
    0 讨论(0)
  • 2021-01-30 20:06

    Yes, it is possible.

    1. Select controllers you want to copy
    2. Press Command + C
    3. Open your second storyboard file
    4. Press Command + V

    Note: "IBOutlets remains as is after copying(Verified on Xcode 6.3.2)."

    0 讨论(0)
  • 2021-01-30 20:06

    If using Cut-n-Paste fails for you, there is a workaround. Paste will fail if there is now ViewController in the file that is being pasted in. That makes it impossible to select the storyboard for pasting. XCode will refuse to paste. So you need to first drag in an empty view controller into the storyboard from the library. Then select this viewController in the storyboard and then the paste will work. After you are done pasting you can delete the dummy viewController. You won't need it again.

    0 讨论(0)
提交回复
热议问题