Create a New Project in Xamarin Studio

Start by creating an iOS solution in Xamarin Studio using the iPhone Empty Project template just like you did last time when following the Xamarin article, Creating iOS Applications in Code. Name the project CurrentWeatherClock.

Xamarin Studio will create a new solution, open it, and open the AppDelegate.cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace CurrentWeatherClock
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
UIWindow window;
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// create a new window instance based on the screen size
window = new UIWindow (UIScreen.MainScreen.Bounds);
// If you have defined a root view controller, set it here:
// window.RootViewController = myViewController;
// make the window visible
window.MakeKeyAndVisible ();
return true;
}
}
}

If you build and run, you’ll get a black screen and an error message in the console window of Xamarin Studio:

Application windows are expected to have a root view controller at the end of application launch

Create a Custom View Controller

Add a new class named CurrentWeatherClockViewController via one of the following methods:

Select menu File > New > File

Press Command-N

Right click on the project and select menu option Add > New File…

Edit your new class to add the MonoTouch.UIKit namespace and inherit from UIViewController: