我有一个简单的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
的值,程序就可以正常工作。