In followup to Where has "window-based" project gone?, what are the steps needed to modify an empty application to a window-based application in MonoTouch using Xcode 4.2?
I am learning iOS development and have read about 1 1/2 books (most recently, “iOS Programming: The Big Nerd Ranch Guide (2nd Edition)” — nice book). I found instructions here on converting an empty application to a window-based application for Objective-C.
I tried applying these steps to a sample MonoTouch application and I get run-time errors related to needing a root view controller.
Is there a site that lists the steps in small words for simple minds?
Here are the steps I discovered by downloading a window-based application sample from the source code of one of my Monotouch books (http://www.apress.com/9781430231745) and then creating an empty solution. I compared the files and added the things needed to the empty one to make it look (and act) like the window-based one.
Change the line
UIApplication.Main (args, null, "AppDelegate");in Main toUIApplication.Main (args);.Add an AppDelegate-derived class to the file
Main.cs(inside the namespace):// 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; } }Remove the file
AppDelegate.cs(delete it from the project).Add a new
Empty iPhone Interface Definitionfile and name itMainWindow.xib.Add a new empty C# file and name it
MainWindow.xib.designer.cs. Insert the following code:using MonoTouch.Foundation; namespace MY_NAMESPACE { [Register ("AppDelegate")] partial class AppDelegate { [Outlet] MonoTouch.UIKit.UIWindow window { get; set; } void ReleaseDesignerOutlets () { if (window != null) { window.Dispose (); window = null; } } } }Change
MY_NAMESPACEto your namespace.Open
MainWindow.xibin the Interface Builder (Xcode 4.2).Change the class for the File’s Owner to
UIApplication(third tab – Identity Inspector).Add a new
Objectobject (search forobjectin the widgets list) and change the class toAppDelegate.Add a new
Windowobject.Select the File’s Owner, click the last tab in the inspectors (Connections Inspector) and connect the delegate link to the
App Delegate.Select the App Delegate and connect the window link to your new window.
Save the MainWindow.xib file changes in Interface Builder.
Return to MonoDevelop.
Open the file
Info.plistand change the Main Interface toMainWindow.I’m getting a warning about
Applications are expected to have a root view controller at the end of application launch, but the application seems to run. I suspect that the warning is coming from some difference in the.xibfile. Perhaps the Xcode 3.2 version includes some indication that this is the root view controller. How do I get rid of this warning?