在选定的tableview rowselected上加载DetailViewcontroller类。
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
if (OnRowSelected != null) {
OnRowSelected (this, new RowSelectedEventArgs (tableView, indexPath));
}
var detailController = new DetailViewController ();
UINavigationController controller = new UINavigationController();
controller.PushViewController(detailController, true);
}
无法加载DetailViewController。
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
方法位于UITableViewSource
有没有办法在rowSelected上加载DetailViewController。
答案 0 :(得分:2)
创建表时,需要将其放在导航控制器的上下文中。
UINavigationController nav = new UINavigationController(myTableViewController);
然后,当您想要显示DetailViewController时,可以将其推送到现有的Navigation控制器上。但是,默认情况下,您的TableSource无权访问NavigationController - 您需要在创建TableSource时传递对TableView控制器的引用,以便TableSource可以访问NavigationController:
// in your controller, when you assign the source
this.TableView.Source = new MyTableViewSource(this);
// in your source, keep a class level ref to the parent
MyTableViewController _parent;
// your Source's constructor
public MyTableViewSource(MyTableViewController parent) {
_parent = parent;
}
// finally, in your RowSelected use the _parent reference to access the Nav controller
var detailController = new DetailViewController ();
_parent.NavigationController.PushViewController(detailController, true);