# Adding the iOS View for the first ViewModel

Keep in mind that although you can place multiple view controllers on one storyboard, the better way to use `MvvmCross` for iOS is to create one storyboard per view, which unify the navigation pattern with the other platforms. So we can have a clear structure, rather than placing multiple views in one storyboard.

To build and debug the iOS App, you need to pair to Mac first. When you build the project, you might encounter an error that is:

> Could not find any available provisioning profiles for iOS.

Open options dialog of VS 2017 and select Xamarin > Apple Accounts, then click the `Install Fastlane` button. Also, make sure to check the Remote Simulator to Windows checkbox so we can use the iOS simulator on our Windows.

![](https://847068821-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LPK_0Nj6gmm5SSTHfcs%2F-LPPEVYp1tmSZDQktHbR%2F-LPPMPyQg-viLi6JRr49%2Fimage.png?alt=media\&token=0e00e7fa-e63b-4b33-a828-b8c2c4bacf77)

Create a new folder called `Views` into the root folder of the `MvvmCrossDemo.iOS` project. Then create an empty `StoryBoard` called `FirstView.storyboard` to the `Views` folder:

![](https://847068821-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LPK_0Nj6gmm5SSTHfcs%2F-LPomXlUgF8kG_xXf9vM%2F-LPonyVUeKnnopncw-Nv%2Fimage.png?alt=media\&token=10c6c1be-a5c9-4aad-a501-72e140a5b1dd)

Use the designer and drag a `ViewController` from the Toolbox to the  `FirstView.Storyboard` like this:

![](https://847068821-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LPK_0Nj6gmm5SSTHfcs%2F-LPPEVYp1tmSZDQktHbR%2F-LPPLaiuVCbIL7-Zvodb%2Fimage.png?alt=media\&token=426e67cf-b8ac-4ee2-b988-7cb478512096)

Click the bottom bar of the `ViewController` to select it:

![](https://847068821-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LPK_0Nj6gmm5SSTHfcs%2F-LPPMSh8LQ3bjmS_sP1g%2F-LPPM_d2D7-7XvA7t7L6%2Fimage.png?alt=media\&token=085c2cf2-9cec-4af8-b3fd-37489ace87ae)

Then set the Class property and the Storyboard ID of it to `FirstView`. Make sure the Use Storyboard ID checkbox is checked, as shown below:

![](https://847068821-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LPK_0Nj6gmm5SSTHfcs%2F-LPPEVYp1tmSZDQktHbR%2F-LPPLi9zsr8AHBOKgjXh%2Fimage.png?alt=media\&token=9e3236a5-a79e-4166-a85f-cc14927cac7d)

Then it will create two associated files: the `FirstView.cs` and the `FirstView.designer.cs`. Move them to the `Views` folder. Change the namespace of the `FirstView.cs`  and the `FirstView.designer.cs` from `Blank` to `MvvmCrossDemo.iOS.Views`. Update the `FirstView` class to inherit from `MvxViewController<FirstViewModel>`, and add an attribute called `MvxFromStoryboard` with a parameter `FirstView` , which indicates the name of the storyboard file, as shown below:

```csharp
using MvvmCross.Binding.BindingContext;
using MvvmCross.Platforms.Ios.Views;
using MvvmCrossDemo.Core.ViewModels;
using System;

namespace MvvmCrossDemo.iOS.Views
{
    [MvxFromStoryboard("FistView")]
    public partial class FirstView : MvxViewController<FirstViewModel>
    {
        public FirstView (IntPtr handle) : base (handle)
        {
        }

    }
}
```

The Xamarin Designer for iOS allows us to drag and drop controls to edit the UI. Also, we can use it to set up the event handlers. Drag some controls from the Toolbox and place them on the `ViewController`:

* A `Lable` control. Set the `Text` property to `Your Name`;&#x20;
* A `Text Field` control to accept the input from users. Set the `Name` property to `txtUserName`;&#x20;
* A `Button` to respond the click event. Set the `Name` property to `btnShowGreeting` and the `Title` property to `Click Me!` .
* A `Label` to show the greeting message. Set the `Name` property to `lblGreeting`.

The controls must have the names so it can be accessed in the code. Now we have an UI like this:

![](https://847068821-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LPK_0Nj6gmm5SSTHfcs%2F-LPPMSh8LQ3bjmS_sP1g%2F-LPPNJ95PNdrWpPcNMBi%2Fimage.png?alt=media\&token=d33c2f0c-8305-446c-b844-01a151d1a24e)

The `FirstView.designer.cs` file is generated by iOS Designer to map the visually-constructed interface to code. Usually, do not modify this file manually. But sometimes, I found that the namespace of this file cannot be updated correctly if you update the namespace of the `FirstView.cs` file. So be carefully to check it and make sure they have the same namespace.
