简体   繁体   中英

Xamarin.IOS Import existing storyboard

I am using Xamarin.IOS to develop an iOS mobile app. I have an existing native Storyboard that I am trying to utilize. Is it possible to import an existing Xcode Storyboard into the Xamarin project?

This will get you started:

  1. Add the storyboard files to your project
  2. Open project Options; add reference to storyboard in IOS Application => iPhone / iPod Deployment Info => Main Interface
  3. Add attribute [Register ("YourViewController")] to class declaration. Add outlets, etc.

If you want the project to have similar structure to the way Xamarin Studio would have created the project, put your Register attribute and outlets, etc, in a separate partial class file named YourViewController.designer.cs and move it under the main class file (drag it onto the main class file).

I had the excercise to rename a solution. This is currently not possible. Therefore I created a new solution (with the final name I wanted to have). In Xamarin Studio I added the files (view controller together with designer.cs files, storyboards, ...). Don't copy it in the file structure only because it's somehow stored in the project options. The designer.cs files have to be put under the view controller files to get the same structure Xamarin uses.

To get everything to work you have to adapt the namespace in the view controller and in the designer.cs files! You should make shure that the correct storyboards are loaded (Project options -> iOS Application -> iPhone/iPod Deployment Info -> Main Interface) as Terry Westley stated.

You could also load the storyboard by code

Storyboard = UIStoryboard.FromName ("MainStoryboard_iPhone", null);

Now my view controller and storyboard works as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM