gpt4 book ai didi

c# - RowSelected - NullReferenceException

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:47:18 26 4
gpt4 key购买 nike

我正在尝试这样做,当我在 UITableView 上按下一行时,它会将一些数据发送到另一个 UIViewController 并生成一个序列。

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

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

错误似乎显示在这里:

viewController.NavigationController.PushViewController (detail, true);

这是我的“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 属性为空。根据 iOS UIViewController 引用 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.

显然,该 View Controller 不是 UINavigationController 堆栈的一部分。

关于c# - RowSelected - NullReferenceException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19877884/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com