1
votes

The new style of applications in iOS5, where you must set the RootViewController on the UIWindow, is getting me very confused.

I've downloaded the latest MonoTouch.Dialog library from here:

https://github.com/migueldeicaza/MonoTouch.Dialog

But when I tried to compile and run the included "Sample" project on the Simulator, it crashes and returns the following error:

Error: Applications are expected to have a root view controller at the end of application launch

I then opened an issue on GitHub:

https://github.com/migueldeicaza/MonoTouch.Dialog/issues/65

But Miguel answered me that:

If you use the new style of applications in iOS5, you must set the RootViewController on the UIWindow. That is a new iOS 5 feature part of the cleanup to bring UIViewController containing into place.

I tried to assign the Navigation controller of the Sample application to the window root view controller, but with no effect. Still getting the same error. This is the FinishedLaunching method of the included Sample application:

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        var Last = new DateTime (2010, 10, 7);
        Console.WriteLine (Last);

        var p = Path.GetFullPath ("background.png");
        window.AddSubview (navigation.View);

         //ADDING THE Navigation Controller as RootViewController
        window.RootViewController = navigation; //THIS LINE WAS ADDED BY ME

        var menu = new RootElement ("Demos"){
            new Section ("Element API"){
                new StringElement ("iPhone Settings Sample", DemoElementApi),
                new StringElement ("Dynamically load data", DemoDynamic),
                new StringElement ("Add/Remove demo", DemoAddRemove),
                new StringElement ("Assorted cells", DemoDate),
                new StyledStringElement ("Styled Elements", DemoStyled) { BackgroundUri = new Uri ("file://" + p) },
                new StringElement ("Load More Sample", DemoLoadMore),
                new StringElement ("Row Editing Support", DemoEditing),
                new StringElement ("Advanced Editing Support", DemoAdvancedEditing),
                new StringElement ("Owner Drawn Element", DemoOwnerDrawnElement),
            },
            new Section ("Container features"){
                new StringElement ("Pull to Refresh", DemoRefresh),
                new StringElement ("Headers and Footers", DemoHeadersFooters),
                new StringElement ("Root Style", DemoContainerStyle),
                new StringElement ("Index sample", DemoIndex),
            },
            new Section ("Auto-mapped", footer){
                new StringElement ("Reflection API", DemoReflectionApi)
            },
        };

        var dv = new DialogViewController (menu) {
            Autorotate = true
        };
        navigation.PushViewController (dv, true);               

        window.MakeKeyAndVisible ();

        return true;
    }

The only line of code I've added is the one indicated in the comments, but this addition doesn't seem to solve the error. Is there something I'm missing?

Thanks in advance!

3
Do you mean you can't compile MT.D (form GIT) using MT5 and make it work on the iOS (5) simulator ? and that's why you're adding this (single) line of code ?poupou
Yes. I'm trying to compile the MonoTouch.Dialog Sample project using MonoTouch 5.0. But I get a crash and that error. Does anyone tried to compile it with MonoTouch 5.0?Emanuele Sabetta
I get this error as well on a MonoGame project I'm working on (because the View/Controllers are all hidden in MonoGame). However, nothing crashes, I just get a "warning" message on the console. Are you sure it's not crashing somewhere else?jonathanpeppers

3 Answers

5
votes

I have updated the sample in MonoTouch.Dialog to show how to add the view controller to both iOS 4.x systems and 5.x systems and should fix this problem.

The short version is that window.AddSubview (navigation.View) is the iOS 4.3 way of doing things, with new versions you need to set the window.RootViewController property, like this:

        if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
            window.RootViewController = navigation; 
        else
            window.AddSubview (navigation.View);            
1
votes

Ok, it seems that Miguel uploaded a new version of the library. He commented the commit with "Update to MonoDevelop 2.8".

https://github.com/migueldeicaza/MonoTouch.Dialog/commit/25974c5c28d31c022d232a449ef9fbc766506701

Now the Sample works fine (you still need to manually set the MainWindow as Main Interface in the Info.plist file to make the error go away. Last time it wasn't enough.).

It seems that the problem was in the project settings, not in the rootviewcontroller thing. It works fine even without one in the end (maybe somebody more expert can explain this strange thing). Unfortunately the error messages of MonoDevelop were misleading!

0
votes

Try removing the window.AddSubview(navigation.View); line.