RowSelected - NullReferenceException [英] RowSelected - NullReferenceException

查看:64
本文介绍了RowSelected - NullReferenceException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图这样做,当我在 UITableView 上按下一行时,它会将一些数据发送到另一个 UIViewController 并创建一个序列.

I am trying to make so when I press a row on my UITableView, it will send some data to another UIViewController and make a seque.

但是在测试时,它给了我:

However when testing it out, it gives me:

System.NullReferenceException 已抛出对象引用未设置到一个对象的实例

System.NullReferenceException has been thrown Object reference not set to an instance of an object

错误似乎显示在这里:

viewController.NavigationController.PushViewController (detail, true);

这是我的RowSelected"

Here is my "RowSelected"

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);
}

异常捕获:

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 行

viewController.NavigationController.PushViewController (detail, true);

Main.cs 第 16 行

UIApplication.Main (args, null, "AppDelegate");

推荐答案

您的 viewController.NavigationController 属性为 null.根据 iOS UIViewController 参考 这里

Your viewController.NavigationController property is null. According to iOS UIViewController reference here

如果接收器或其祖先之一是导航的孩子控制器,此属性包含拥有的导航控制器.如果视图控制器未嵌入在导航控制器.

If the receiver or one of its ancestors is a child of a navigation controller, this property contains the owning navigation controller. This property is nil if the view controller is not embedded inside a navigation controller.

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

Apparently, that view controller is not part of a UINavigationController stack.

这篇关于RowSelected - NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆