【发布时间】:2015-12-20 16:49:30
【问题描述】:
我确信这可能是一个非常简单的解决方案,但总的来说,我对 xamarin 和 c# 还是很陌生。我创建了一个表格视图,当按下该视图中的一个单元格时,我希望它导航到一个名为 SecondViewController() 的新视图。我的 ViewController.cs 中有以下类
public void changeview()
{
SecondViewController controller = this.Storyboard.InstantiateViewController("SecondViewController") as SecondViewController;
this.NavigationController.PushViewController(controller, true);
}
然后在我的 TableSource.cs 类中,我有以下代码来调用 changeview()
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
ViewController view = new ViewController();
view.changeview();
tableView.DeselectRow(indexPath, true);
}
编译时没有错误,但运行时出现以下代码错误
SecondViewController controller = this.Storyboard.InstantiateViewController("SecondViewController") as SecondViewController;
读取
System.NullReferenceException: Object reference not set to an instance of an object
为什么这不起作用?如果我在按钮类中使用相同的代码,它效果很好,为了测试以确保我正确调用了类,我将 changeview() 中的代码更改为 UIAlertView,当按下单元格时,alertview 工作。我不知道从这里去哪里,可能有更好的方法来为此目的改变视图?非常感谢任何帮助!
【问题讨论】:
标签: c# uitableview xamarin uinavigationcontroller