0
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 プロジェクトに取り組んでいます。そのため、ボタンのポップアップとしてテーブルビューがあります。それをクリックすると、3 つのオプションがあります。1 つを選択すると、ボタンのラベルが選択したオプションに置き換えられます。選択された行は、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);
       }
 .....
}

これは、ドロップダウン用にテーブルを設定する popovercontroller です。つまり、ここの値はドロップダウンに取り込まれます..

EDIT2:

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

1 に答える 1

1

RowSelected メソッドで DetailViewController の新しいインスタンスを作成しています。必要なのは、既に存在する DetailViewController への参照です。

TableViewController を作成するときは、「親」の DetailViewController への参照を渡す必要があります。そうすれば、RowSelected メソッドで、既存の DVC でメソッドを呼び出すことができます。

于 2013-02-15T01:38:40.243 に答える