未将对象引用设置为单点触控中的对象实例 [英] Object reference not set to an instance of an object in monotouch
问题描述
NavigationController 当我想从一个页面导航到另一个页面时采用空参数.这是我的代码:
NavigationController Takes null arguments when i want to navigate from one page to another page. Here is my code:
var detail = Viewcontroller.Storyboard.InstantiateViewController("FullgalleryimagesStoryBoardId") as fullgalleryimageinfo;
Viewcontroller.NavigationController.PushViewController (detail, true);
Viewcontroll 和 storyboard 正确接受参数,但 NavigationController 会抛出类似上面的异常
Viewcontroll and storyboard takes arguments correctly but NavigationController throws an exception like above
我能做什么?
try
{
UINavigationController Navigationcontroller=new UINavigationController();
var detail = Viewcontroller.Storyboard.InstantiateViewController("FullgalleryimagesStoryBoardId") as fullgalleryimageinfo;
// Viewcontroller.NavigationController.PushViewController (detail, true);
Navigationcontroller.PushViewController(detail,true);
}
catch (Exception ex)
{
string exep=ex.Message;
}
我试过这个代码片段,没有例外,但没有完成页面导航.
i tried this code snippet there is no exception but there is no page navigation is done.
推荐答案
如果您的 detail
变量为空,那么故事板中不存在 ID 为FullgalleryimagesStoryBoardId"的控制器,或者它存在,但不是 fullgalleryimageinfo
类型.
If your detail
variable is null, then either a controller with the ID "FullgalleryimagesStoryBoardId" does not exist in the story board, or it exists, but it is not of type fullgalleryimageinfo
.
尝试以下操作并在该行后添加断点:
Try the following and add a breakpoint after the line:
var detail = Viewcontroller.Storyboard.InstantiateViewController("FullgalleryimagesStoryBoardId");
如果detail
为空,则ID错误.如果它不为空,则它是不同的类型,在这种情况下,您必须正确设置类型.
If detail
is null, then the ID is wrong. If it is not null, then it is of a different type, in which case you have to set the type correctly.
这是在 Xcode 中的操作方法:
Here is how to do it in Xcode:
https:///www.dropbox.com/s/8qu62ncjehk7p8i/Screenshot%202017-02-09%2010.48.04.png?dl=0
这篇关于未将对象引用设置为单点触控中的对象实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!