MonoTouch: UITableViewController,NavigationController在Naviga



我正在使用以下策略构建一个基于窗口的(所有UI以编程方式连接,没有IB) MonoTouch应用程序:

伪代码:

 Note: I'm not calling base.ViewDidLoad on any of the ViewDidLoad calls, 
 nor calling any base constructors of any ViewController 
 subclass I've implemented. 
 AppDelegate : UIApplicationDelegate
      FinishedLaunching() 
             window.AddSubView(tabbarController.View)
 TabbarController : UITabbarController
       ViewDidLoad() 
              ViewControllers[0] = myNavigationController
 MyNavigationController : UINavigationController
       ViewDidLoad()
             PushViewController(myTableViewController,false)
 MyTableViewController : UITableViewController
        ViewDidLoad() 
             //Property NavigationController is NULL.

根据developer.apple.com,一个人应该使用名为initWithRootController的ObjC init方法来创建NavigationControllers,但我找不到任何MonoTouch等效的方法。

Ref http://developer.apple.com/library/ios/文档/用户体验/概念/TableView_iPhone/TableViewAndDataModel TableViewAndDataModel.html

MyNavigationControllers PushViewController方法不应该自动分配MyTableViewController实例的NavigationController属性吗?在自动装配过程中,我还缺什么吗?

其他一切都按预期工作。非常感谢MT团队!:)

谢谢!

当您创建myNavigationController的实例时,您是如何这样做的?我相信c#中等价于initWithRootController的是:

UINavigationController navController = new UINavigationController(rootViewController);

要在您的自定义UINavigationController中实现此功能,您必须沿着以下行创建一个新的构造函数:

MyNavigationController(UIViewController rootViewController)
{
    ViewControllers = new UIViewController[1] { rootViewController };
}

这将为你设置rootViewController。您需要从ViewDidLoad方法中移除PushViewController。通过PushViewController推送的任何后续视图控制器都会自动为你设置这个NavigationController属性。

最新更新