Iphone Xamarin UITableView行选择

Iphone Xamarin UITableView行选择,iphone,uitableview,xamarin.ios,xamarin,Iphone,Uitableview,Xamarin.ios,Xamarin,我有一个简单的UITableView,我通过实现UITableViewSource来加载数据。我在同一页上也有一个标签。我想在标签上显示tableview中选定的行。 这是我的MainViewController: public override void ViewDidLoad () { base.ViewDidLoad (); List<string> lstTableSource = new List<string> (); for (int

我有一个简单的
UITableView
,我通过实现
UITableViewSource
来加载数据。我在同一页上也有一个标签。我想在标签上显示tableview中选定的行。 这是我的
MainViewController

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();
    List<string> lstTableSource = new List<string> ();
    for (int intCounter=0; intCounter<5; intCounter++) 
    {
        lstTableSource.Add ("Row "+intCounter);
    }
    tblTest.Source = new TableSource (lstTableSource.ToArray());
}

public void Test(string strSelected)
{
    lblTest.Text = strSelected;
}
当我点击行时,系统正在启动NullReferenceException

lblTest.Text=strSelected


如果我在控制台上打印变量
strSelected
的值,程序工作正常。

lblTest在哪里声明和实例化?与其将父控制器的引用传递给表源,不如创建表源分派的事件。然后,您可以让控制器侦听此事件,并通过在UITableSource上定义的getter访问所选项目。这将导致更好的解耦,允许您将UITableSource用于多个UIController。@Jason标签是从xib添加的。@BenBishop感谢您的建议。“我一定要试试看。”本毕晓普说得对!非常感谢你。你救了我一天。
public override void RowSelected (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
    MainViewControllerObj.Test (tableItems[indexPath.Row]);
}