gpt4 book ai didi

ios - 在 tableviewsource 上选择的 Monodevelop 行导致空引用异常

转载 作者:行者123 更新时间:2023-11-29 04:07:59 24 4
gpt4 key购买 nike

public delegate bool SelectedValueForDropDown (string name);
public partial class BasicTableViewSource : UITableViewSource
{
public override void RowSelected(UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
SelectedValueForDropDown selValue;
// Do something for the selected row
string itemSel = this._tableItems[indexPath.Section];
Console.WriteLine("90 the item selected is :{0}",itemSel);

DetailViewController dvc = new DetailViewController();
selValue = dvc.SelectedValueForPosition;
//bool val = dvc.SelectedValueForPosition(itemSel);
ValueSelectedDD valDD = new ValueSelectedDD();

bool success = valDD.HandleValueSelected(selValue);
Console.WriteLine("100 the value is : {0}",success);
}
.....
} //class closed

public class ValueSelectedDD
{
public bool HandleValueSelected (SelectedValueForDropDown selValue)
{
bool success =false;
success = selValue("CEO");

return success;
}
}
//This method is in DetailViewController.designer.cs class.
public bool SelectedValueForPosition (string name)
{
Console.WriteLine("the value selected is :{0}",name);
btnPosition.SetTitle(name,UIControlState.Normal); //Exception occurs here
return true;
}

我正在开发简单的 MonoDevelop 项目。所以我的按钮有一个弹出的表格 View 。我点击它,我有 3 个选项。我选择一个,按钮的标签应该被所选选项替换。所选行位于 tableviewsource 类中。 DetailViewController 是我有要单击的实际按钮的类。我遇到了异常

System.NullReferenceException: Object reference not set to an instance of an object

at EmployeeWithDropDown.DetailViewController.SelectedValueForPosition (System.String name) [0x0000b] in /Users/.../EmployeeWithDropDown/EmployeeWithDropDown/DetailViewController.designer.cs:106

at EmployeeWithDropDown.ValueSelectedDD.HandleValueSelected (EmployeeWithDropDown.SelectedValueForDropDown selValue) [0x00002] in /Users/.../EmployeeWithDropDown/EmployeeWithDropDown/BasicTableViewSource.cs:109
at EmployeeWithDropDown.BasicTableViewSource.RowSelected (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00036] in /Users/.../EmployeeWithDropDown/EmployeeWithDropDown/BasicTableViewSource.cs:99

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 EmployeeWithDropDown.Application.Main (System.String[] args) [0x00000] in /Users/.../EmployeeWithDropDown/EmployeeWithDropDown/Main.cs:17

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

如果您需要更多信息,请询问。谢谢。

编辑:

public partial class PopoverContentViewcontroller : UIViewController
{
public override void ViewDidLoad ()
{

base.ViewDidLoad ();
table = new UITableView(View.Bounds);
table.AutoresizingMask = UIViewAutoresizing.All;
string[] tableItems = new string[]{"CEO","Developer","IT"};
//List<String> wordList = Arrays.asList(words);
List<string> lst = new List<string>(tableItems);

table.Source = new BasicTableViewSource(lst);
Add (table);
}
.....
}

这是填充下拉列表的弹出 Controller 。即这里的值被填充在下拉列表中..

编辑2:

                    DetailViewController dvc;
.....
table.Source = new BasicTableViewSource(lst,dvc);
Add (table);

最佳答案

您正在 RowSelected 方法中创建 DetailViewController 的新实例。您需要的是对已存在的 DetailViewController 的引用。

当您创建 TableViewController 时,您需要传入对“父”DetailViewController 的引用。这样,您就可以在 RowSelected 方法中调用现有 DVC 上的方法。

关于ios - 在 tableviewsource 上选择的 Monodevelop 行导致空引用异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14882380/

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