开发者

MonoTouch: UITableViewController,NavigationController is null after NavigationController.PushViewController

开发者 https://www.devze.com 2023-03-02 04:28 出处:网络
I\'m building a window-based (all UI programatically wired up, no IB) MonoTouch app using the following strategy:

I'm building a window-based (all UI programatically wired up, no IB) MonoTouch app using the following strategy:

Pseudo code:

 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.

According to developer.apple.com, one should create NavigationControllers using a ObjC init method named initWithRootController, but I could not find any MonoTouch equivalent of doing this.

Ref http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/TableViewAndDataModel/TableViewAndDataModel.html

Should not MyNavigationCon开发者_如何学JAVAtrollers PushViewController method autoassign the NavigationController property of the MyTableViewController instance? Is there anything I might be missing to get this autowiring going?

Everything else works as expected. Very grateful to the MT team! :)

Thanks!


When you create the instance of myNavigationController how are you doing so? I believe the C# equivalent for initWithRootController is:

UINavigationController navController = new UINavigationController(rootViewController);

To implement this in your custom UINavigationController you would have to create a new constructor along the lines of:

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

This would set the rootViewController for you. You would need to remove the PushViewController from the ViewDidLoad method. Any subsequent ViewControllers pushed via PushViewController will have this NavigationController property automatically set for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消