MonoTouch和应用程序在应用程序启动结束时应该有一个根视图控制器.错误
本文关键字:应用程序 有一个 视图 控制器 错误 启动 结束 MonoTouch | 更新日期: 2023-09-27 18:13:38
iOS5中应用程序的新风格,你必须在ui窗口上设置RootViewController,这让我非常困惑。
我已经下载了最新的MonoTouch。对话框库: https://github.com/migueldeicaza/MonoTouch.Dialog但是当我试图在模拟器上编译和运行包含的"样本"项目时,它崩溃并返回以下错误:
错误:应用程序在应用程序启动结束时应该有一个根视图控制器
然后我在GitHub上打开了一个问题:
https://github.com/migueldeicaza/MonoTouch.Dialog/issues/65但是Miguel回答我说:
如果你在iOS5中使用新样式的应用程序,你必须在UIWindow上设置RootViewController。这是iOS 5的一个新功能,将UIViewController包含在适当的位置。
我试图将示例应用程序的导航控制器分配给窗口根视图控制器,但没有效果。还是得到相同的错误。这是示例应用程序的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;
}
我添加的唯一一行代码是注释中指出的那一行,但是这个添加似乎并没有解决错误。我是不是漏掉了什么?
提前感谢!
我已经在MonoTouch中更新了样本。对话框,显示如何将视图控制器添加到iOS 4。X系统和5。X系统,应该解决这个问题。
简而言之就是那个窗口。AddSubview (navigation。view)是iOS 4.3做事情的方式,在新版本中你需要设置窗口。RootViewController属性,像这样:
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
Ok,看来Miguel上传了一个新版本的库。他注释了"Update to MonoDevelop 2.8"。
https://github.com/migueldeicaza/MonoTouch.Dialog/commit/25974c5c28d31c022d232a449ef9fbc766506701现在样本工作良好(您仍然需要手动设置主窗口为主界面的信息。Plist文件使错误消失。上次还不够。
似乎问题是在项目设置,而不是在rootviewcontroller的东西。即使最后没有一个,它也能很好地工作(也许更专业的人可以解释这个奇怪的事情)。不幸的是,MonoDevelop的错误信息是误导!
尝试删除window.AddSubview(navigation.View);
行