C# 单触和;在应用程序启动结束时,应用程序预计会有一个根视图控制器;错误
iOS5中的新型应用程序必须在ui窗口上设置RootViewController,这让我非常困惑C# 单触和;在应用程序启动结束时,应用程序预计会有一个根视图控制器;错误,c#,ios,uiviewcontroller,xamarin.ios,monotouch.dialog,C#,Ios,Uiviewcontroller,Xamarin.ios,Monotouch.dialog,iOS5中的新型应用程序必须在ui窗口上设置RootViewController,这让我非常困惑 if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0)) window.RootViewController = navigation; else window.AddSubview (navigation.View); 我已从此处下载了最新的
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
我已从此处下载了最新的MonoTouch.Dialog库:
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
但当我试图在模拟器上编译并运行包含的“示例”项目时,它崩溃并返回以下错误:
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
错误:在应用程序启动结束时,应用程序应具有根视图控制器
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
然后,我在GitHub上发布了一个问题:
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
但是米格尔回答我说:
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
如果在iOS5中使用新样式的应用程序,则必须在UIWindow上设置RootViewController。
这是iOS5清理的一个新功能部分,用于将UIViewController包含的内容放置到位
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
我试图将示例应用程序的导航控制器分配给窗口根视图控制器,但没有效果。仍然得到相同的错误。这是附带示例应用程序的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;
}
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
我添加的唯一一行代码是注释中指出的代码,但此添加似乎无法解决错误。有什么我遗漏的吗
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
提前谢谢 尝试删除
窗口.AddSubview(navigation.View)代码>行。尝试删除窗口。添加子视图(navigation.View)代码>行。好的,看起来米格尔上传了一个新版本的库。他用“更新到MonoDevelop2.8”对提交进行了评论
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
现在这个示例工作正常(您仍然需要在Info.plist文件中将MainWindow手动设置为主界面,以消除错误。上次还不够)
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
问题似乎出在项目设置上,而不是rootviewcontroller上。即使最后没有一个,它也可以正常工作(也许有更专业的人可以解释这个奇怪的事情)。不幸的是,MonoDevelop的错误消息具有误导性 好吧,看来米格尔上传了图书馆的新版本。他用“更新到MonoDevelop2.8”对提交进行了评论
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
现在这个示例工作正常(您仍然需要在Info.plist文件中将MainWindow手动设置为主界面,以消除错误。上次还不够)
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
问题似乎出在项目设置上,而不是rootviewcontroller上。即使最后没有一个,它也可以正常工作(也许有更专业的人可以解释这个奇怪的事情)。不幸的是,MonoDevelop的错误消息具有误导性 我已在MonoTouch.Dialog中更新了示例,以显示如何将视图控制器添加到iOS 4.x系统和5.x系统,并应解决此问题
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
简短的版本是window.AddSubview(navigation.View)是iOS 4.3的操作方式,在新版本中,您需要设置window.RootViewController属性,如下所示:
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
我已经在MonoTouch.Dialog中更新了示例,以演示如何将视图控制器添加到iOS 4.x系统和5.x系统,并应解决此问题
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
简短的版本是window.AddSubview(navigation.View)是iOS 4.3的操作方式,在新版本中,您需要设置window.RootViewController属性,如下所示:
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
你的意思是你不能用MT5编译MT.D(FormGit)并让它在iOS(5)模拟器上工作吗?这就是为什么你要添加这(单个)行代码?是的。我正在尝试使用MonoTouch 5.0编译MonoTouch.Dialog示例项目。但我遇到了一个崩溃和那个错误。有人试过用MonoTouch 5.0编译它吗?我在一个MonoGame项目中也遇到了这个错误(因为视图/控制器都隐藏在MonoGame中)。但是,没有崩溃,我只是在控制台上收到一条“警告”消息。你确定它没有在其他地方崩溃吗?你的意思是你不能使用MT5编译MT.D(FormGit)并使它在iOS(5)模拟器上工作吗?这就是为什么你要添加这(单个)行代码?是的。我正在尝试使用MonoTouch 5.0编译MonoTouch.Dialog示例项目。但我遇到了一个崩溃和那个错误。有人试过用MonoTouch 5.0编译它吗?我在一个MonoGame项目中也遇到了这个错误(因为视图/控制器都隐藏在MonoGame中)。但是,没有崩溃,我只是在控制台上收到一条“警告”消息。你确定它没有在其他地方崩溃吗?感谢你的解释,通过更改项目文件和设置主界面文件对我有效。感谢你的解释,通过更改项目文件和设置主界面文件对我有效。