Novell's MonoTouch has support for Apple's new iPad!
Downloads
Start by checking out MonoTouch's iPad landing page. To get started, you will need to do the following:
- Apple's iPhone SDK 3.2 Beta with Xcode 3.2.2 (iphone_sdk_3.2_beta_with_xcode_3.2.2.dmg)
- Mono 2.6.1 for Mac OS X(MonoFramework-2.6.1_1.macos10.novell.x86.dmg)
- MonoTouch SDK 1.x (monotouch-1.9.0.pkg)
- MonoDevelop 2.2.1 (MonoDevelop-2.2.1.dmg)
- Start MonoDevelop and switch the Update level to Alpha (experimental)
- Download MonoTouch 1.9.0 ALPHA
MonoTouch iPad Hello World
Now we can create a new iPad application using MonoDevelop
- File -> New Solution
- Expand C# -> iPad and select iPad Window-based project
- Starting source code in Main.cs
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace HelloWorld
{
public class Application
{
static void Main (string[] args)
{
UIApplication.Main (args);
}
}
// The name AppDelegate is referenced in the MainWindow.xib file.
public partial class AppDelegate : UIApplicationDelegate
{
// This method is invoked when the application has
// loaded its UI and its ready to run
public override bool FinishedLaunching(UIApplication app,
NSDictionary options)
{
// If you have defined a view, add it here
// window.AddSubview (navigationController.View);
window.MakeKeyAndVisible();
return true;
}
}
}
- Double-click MainWindow.xib to open Interface Builder
- Open the Interface Builder Library
- Switch to Inputs & Values
- Drag a Button to the Window
- Drag a Label to the Window
- It should look like this:
- Click on Classes in the Library Tool Window:
We need to connect the UI controls by defining an define outlet in a class. These outlets are mapped into C# properties at runtime. To let the application delegate access the button and the label, we are going to have to connect these controls with it.
- Select AppDelegate:
- Select Outlets:
- Create an Outlet for the Label and Button by clicking on the [+] button in the "Class Outlet" section of that pane:
- Bring the Document Window for MainWindow.xib into focus
- Click App Delegate
- Click App Delegate in the Document Window and notice the button and label in the Document Info Window
- Drag the button Outlet to the Button
- Drag the label Outlet to the Label
- Outlets have now been wired up in Interface Builder and the Document Info Window for the App Delegate should look like the following
- Save and Close Interface Builder
- Wire up the Button's TouchDown() event
The code should look like this:
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace HelloWorld
{
public class Application
{
static void Main (string[] args)
{
UIApplication.Main (args);
}
}
// The name AppDelegate is referenced in the MainWindow.xib file.
public partial class AppDelegate : UIApplicationDelegate
{
// This method is invoked when the application has
// loaded its UI and its ready to run
public override bool FinishedLaunching(UIApplication app,
NSDictionary options)
{
// If you have defined a view, add it here
// window.AddSubview (navigationController.View);
window.MakeKeyAndVisible();
button.TouchDown += HandleButtonTouchDown;
return true;
}
void HandleButtonTouchDown (object sender, EventArgs e)
{
label.Text = "Hello iPad from C#"
}
}
}
- Run the app in the iPad Simulator
Important Interface Builder Note
If you add additional XIB files to your project, you will need to do the following (MainWindow.xib is good by default):
- Click File -> Transition To -> iPad
- Close the old iPhone style XIB
- File->Save As and overwrite the old XIB with the transitioned one
I think MonoTouch is great and makes it really easy to leverage the .NET Framework on the iPhone/iPad stack.