MonoTouch和"应用程序在应用程序启动结束时应该有一个根视图控制器"错误

Ema*_*tta 1 c# uiviewcontroller xamarin.ios ios monotouch.dialog

iOS5中新的应用程序样式,你必须在UIWindow上设置RootViewController,让我非常困惑.

我从这里下载了最新的MonoTouch.Dialog库:

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

但是当我尝试在Simulator上编译并运行包含的"Sample"项目时,它会崩溃并返回以下错误:

错误:应用程序在应用程序启动结束时应具有根视图控制器

然后我在GitHub上打开了一个问题:

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

但米格尔回答我说:

如果在iOS5中使用新样式的应用程序,则必须在UIWindow上设置RootViewController.这是清理的一个新的iOS 5功能部分,它将UIViewController包含在内.

我尝试将Sample应用程序的Navigation控制器分配给窗口根视图控制器,但没有任何效果.仍然得到同样的错误.这是包含的Sample应用程序的FinishedLaunching方法:

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;
    }
Run Code Online (Sandbox Code Playgroud)

我添加的唯一代码行是注释中指示的代码,但这个添加似乎不能解决错误.有什么我想念的吗?

提前致谢!

mig*_*aza 5

我已经更新了MonoTouch.Dialog中的示例,以展示如何将视图控制器添加到iOS 4.x系统和5.x系统,并应解决此问题.

简短的版本是window.AddSubview(navigation.View)是iOS 4.3的服务方式,你需要设置window.RootViewController属性的新版本,如下所示:

        if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
            window.RootViewController = navigation; 
        else
            window.AddSubview (navigation.View);            
Run Code Online (Sandbox Code Playgroud)