0

我有以下 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);
            }
        }
    }

像这样添加:

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) 
        };

这一切都适用于 UITableView - 数据被加载等,但每当我点击一个单元格加载子数据时 - _dvc.NavigationController 为空

有谁知道这是在哪里设置的?或者,如果它是由框架设置的——它怎么会被取消?

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

w://

4

2 回答 2

2

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

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);
于 2010-03-05T07:35:36.573 回答
1

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

public DVCTableViewDelegate (DaysViewController controller, List<DateTime> dates)
{
    this._dvc = controller;
    this.ConferenceDates = dates;
    this.navController = controller.NavigationController;
}

navController 是 UINavigationController 但 dvc.NavigationController 在行选择方法中为空!

陌生感。

于 2010-02-28T17:09:01.747 回答