Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.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/1/php/234.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# UITableViewDelegate存在问题_C#_Iphone_Cocoa Touch_Mono_Xamarin.ios - Fatal编程技术网

C# UITableViewDelegate存在问题

C# UITableViewDelegate存在问题,c#,iphone,cocoa-touch,mono,xamarin.ios,C#,Iphone,Cocoa Touch,Mono,Xamarin.ios,我有以下tableviewdelegate: private class TableViewDelegate : UITableViewDelegate { private DaysViewController _dvc; private List<DateTime> ConferenceDates; public TableViewDelegate (DaysViewController controller, List<

我有以下tableviewdelegate:

private class TableViewDelegate : UITableViewDelegate
    {
        private DaysViewController _dvc;
        private List<DateTime> ConferenceDates;
        public TableViewDelegate (DaysViewController controller, List<DateTime> dates)
        {
            _dvc = controller;
            ConferenceDates = dates;
        }



        /// <summary>
        /// If there are subsections in the hierarchy, navigate to those
        /// ASSUMES there are _never_ Categories hanging off the root in the hierarchy
        /// </summary>
        public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
        {
            string date = ConferenceDates[indexPath.Row].ToShortDateString ();
            Console.WriteLine ("DaysViewController:TableViewDelegate.RowSelected: Label=" + date);

                            /*SessionsViewController sessionsView = new SessionsViewController(date);
            sessionsView.Title = date;
            _dvc.NavigationController.PushViewController(sessionsView,true);*/



            EventsViewController eventsView = new EventsViewController (date);

            eventsView.Title = date;
            try {

                _dvc.NavigationController.PushViewController
                (eventsView, true);

            } catch (Exception ex) {
                Log.Error(ex);
            }
        }
    }
对于UITableView来说,这一切都很好——数据被加载,等等,但每当我点击单元格加载子数据时——dvc.NavigationController为空

有人知道这是从哪里开始的吗?或者,如果它是由框架设置的,那么它怎么会被置空呢

干杯-如果我需要发布更多的代码,请告诉我


w://

奇怪的是-如果我在构造函数中这样做:

public DVCTableViewDelegate (DaysViewController controller, List<DateTime> dates)
{
    this._dvc = controller;
    this.ConferenceDates = dates;
    this.navController = controller.NavigationController;
}
公共DVCTableViewDelegate(DaysViewController控制器,列出日期)
{
这是控制器;
this.ConferenceDates=日期;
this.navController=controller.NavigationController;
}
navController是UINavigationController,但所选方法行中的dvc.NavigationController为null


奇怪。

奇怪的是-如果我在构造函数中这样做:

public DVCTableViewDelegate (DaysViewController controller, List<DateTime> dates)
{
    this._dvc = controller;
    this.ConferenceDates = dates;
    this.navController = controller.NavigationController;
}
公共DVCTableViewDelegate(DaysViewController控制器,列出日期)
{
这是控制器;
this.ConferenceDates=日期;
this.navController=controller.NavigationController;
}
navController是UINavigationController,但所选方法行中的dvc.NavigationController为null


奇异性。

如果要在视图上使用导航控制器,可以通过创建UINavigationController实例并将视图添加到此控制器来实现。然后,您的视图成为UINavigationController的子视图,现在应该可以从TableViewDelegate中访问视图的NavigationController。提供所需的导航控制器。在下面的示例中,作为模态视图控制器

tableView = new UITableView { 
            Delegate = new TableViewDelegate (this, ConferenceDates), 
            DataSource = new TableViewDataSource (this, ConferenceDates), 
            AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth, 
            BackgroundColor = UIColor.Clear, 
            TableHeaderView = navBar, 
            Frame = new RectangleF (0, 0, this.View.Frame.Width, this.View.Frame.Height) 
        };

UINavigationController navController = new UINavigationController(tableView);
navController.ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal;

this.PresentModalViewController(navController, true);

如果要在视图上使用导航控制器,可以通过创建UINavigationController的实例并将视图添加到此控制器来实现。然后,您的视图成为UINavigationController的子视图,现在应该可以从TableViewDelegate中访问视图的NavigationController。提供所需的导航控制器。在下面的示例中,作为模态视图控制器

tableView = new UITableView { 
            Delegate = new TableViewDelegate (this, ConferenceDates), 
            DataSource = new TableViewDataSource (this, ConferenceDates), 
            AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth, 
            BackgroundColor = UIColor.Clear, 
            TableHeaderView = navBar, 
            Frame = new RectangleF (0, 0, this.View.Frame.Width, this.View.Frame.Height) 
        };

UINavigationController navController = new UINavigationController(tableView);
navController.ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal;

this.PresentModalViewController(navController, true);