首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RowSelected - NullReferenceException

RowSelected - NullReferenceException
EN

Stack Overflow用户
提问于 2013-11-09 15:52:58
回答 1查看 1.4K关注 0票数 3

当我按下UITableView上的一行时,它会将一些数据发送到另一个UIViewController并创建一个seque。

然而,在测试它时,它给了我:

System.NullReferenceException已被抛出对象引用,但未设置为对象的实例。

这个错误似乎显示在这里:

代码语言:javascript
复制
viewController.NavigationController.PushViewController (detail, true);

这是我的"RowSelected“

代码语言:javascript
复制
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
    Console.WriteLine ("Row: " + tableItems [indexPath.Row].Heading);

    //new UIAlertView("Row Selected", tableItems[indexPath.Row].Heading, null, "OK", null).Show();
    tableView.DeselectRow (indexPath, true);

    // Specially for Storyboard !!
    var detail = viewController.Storyboard.InstantiateViewController("detail") as HolsteinItemViewController;
    detail.Title = tableItems[indexPath.Row].Heading;
    detail.LoadUrl (tableItems[indexPath.Row].SubHeading);
    viewController.NavigationController.PushViewController (detail, true);
}

被发现的例外:

代码语言:javascript
复制
System.NullReferenceException: Object reference not set to an instance of an object
  at Holstein.TableSource.RowSelected (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x0008e] in /Users/Emil/Projects/Holstein/Holstein/Code/TableSource.cs:41
  at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at Holstein.Application.Main (System.String[] args) [0x00008] in /Users/Emil/Projects/Holstein/Holstein/Main.cs:16

TableSource.cs第46行

代码语言:javascript
复制
viewController.NavigationController.PushViewController (detail, true);

Main.cs第16行

代码语言:javascript
复制
UIApplication.Main (args, null, "AppDelegate");
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-10 16:37:28

您的viewController.NavigationController属性为空。根据iOS UIViewController reference 这里

如果接收方或其祖先之一是导航控制器的子级,则此属性包含拥有的导航控制器。如果视图控制器未嵌入导航控制器中,则此属性为零。

显然,该视图控制器不是UINavigationController堆栈的一部分。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19877884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档