我正在使用iOS设计器,并且我有一个带有不同视图的故事板(导航控制器,...)。在几乎每个视图的底部右侧都有一个红色感叹号。我得到这样Xamarin Studio上iOS设计器中感叹号的含义
System.NullReferenceException
对象引用错误不设置到对象的实例
如果我去相应的代码行:
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return TopViewController.GetSupportedInterfaceOrientations();
}
这是部分我的CustomNavigationController
。如果我在iOS设计器上设置类名称,则会出现错误。我需要在这里添加什么?构造函数如下所示:
public CustomNavigationController (IntPtr handle) : base (handle)
{
}
我是否必须在AppDelegate中实例化它?
在另一个视图控制器我得到一个类似的异常(有不同的堆栈),并指向我这一行:
this.NavigationController.NavigationBar.TintColor = UIColor.FromRGB (21, 66, 139);
的应用程序似乎是工作在模拟器,虽然对设备的罚款。
如何解决此问题?
编辑:
我现在在我的视图控制器删除代码:
this.NavigationController.NavigationBar.TintColor = UIColor.FromRGB (21, 66, 139);
作为替代我搬到这个代码的应用程序委托FinishedLaunching()
:
UINavigationBar.Appearance.TintColor = UIColor.FromRGB (21, 66, 139);
结果是,现在我没有这个视图控制器的感叹号和颜色是所需的。但iOS Designer中的预览不再显示正确的颜色。
如果我在CustomNavigationController
中注释掉GetSupportedInterfaceOrientations()
,则表示其他感叹号已被删除。我想我需要这个函数来定义每个视图控制器的方向。快速查看表明,它似乎工作。
感谢我不知道的信息。所以我应该在设计模式下添加一个默认方向?这是否也适用于访问'this.NavigationController'?我不知道为什么我无法访问导航控制器。在iOS设计器中,此视图上缺少导航栏。 – testing 2014-09-03 14:36:09
现在我试图使用这种方法,但我仍然在iOS设计器中得到'System.NullReferenceException' ...这里是代码'if(Site!= null && Site.DesignMode){UI}返回UIInterfaceOrientationMask.Portrait; } else { return TopViewController.GetSupportedInterfaceOrientations(); }' – testing 2014-09-03 14:47:58
我再次尝试了一个字符串。我得到了'UIViewControllerHierarchyInconsistency'。这种方法不起作用。 – testing 2014-09-05 08:59:03