Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从xamarin中选定的tableview行加载ViewController_C#_Ios_Iphone_Xamarin_Tableview - Fatal编程技术网

C# 无法从xamarin中选定的tableview行加载ViewController

C# 无法从xamarin中选定的tableview行加载ViewController,c#,ios,iphone,xamarin,tableview,C#,Ios,Iphone,Xamarin,Tableview,在选定的tableview行上,选择加载DetailViewcontroller类 public override void RowSelected (UITableView tableView, NSIndexPath indexPath) { if (OnRowSelected != null) { OnRowSelected (this, new RowSelectedEventArgs (tableView,

在选定的tableview行上,选择加载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


是否有办法在选定的行上加载DetailViewController。

创建表时,需要将其放置在导航控制器的上下文中

public override void RowSelected (UITableView tableView, NSIndexPath indexPath) 
UINavigationController nav=新的UINavigationController(myTableViewController)

然后,当您想显示DetailViewController时,可以将其推送到现有的导航控制器上。但是,默认情况下,您的表源没有对NavigationController的访问权限-您需要在创建表源时传递对TableView控制器的引用,以便表源可以访问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);

为什么要创建
UINavigationController
的新实例?@Larme DetailViewController DetailViewController=new DetailViewController();NavigationController.PushViewController(detailViewController,true);它显示了一个错误。。当前上下文中不存在NavigationController。所以我创建了UINavigationController对象。