Xamarin UITableView RowSelection

时间:2013-08-14 12:06:00

标签: iphone uitableview xamarin.ios xamarin

我有一个简单的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;
}

这是TableSource.cs

中的行选择方法
public override void RowSelected (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
    MainViewControllerObj.Test (tableItems[indexPath.Row]);
}

当我点击行系统时会抛出NullReferenceException

  

lblTest.Text = strSelected;

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

0 个答案:

没有答案