开发者

How to use UIViewController of a separate XIB with outlet in AppDelegate.cs? Outlet is always NULL

Weird thing here. I think I have done it before but it no longer seems to work. Environment is now: Lion, MT 4.1, MD 2.6 RC, Xcode 3's Interface Builder.

  • I have a universal app (template from MonoDevelop).
  • I changed it to have one AppDelegateBase class where both, the iPhone and the iPad's app delegate inherit from.
  • There is one MasterController.xib file that contains a UITabBarController.
  • In IB I set the file's owner of this XIB to AppDelegateBase.
  • I added a UITabBarController outlet and connected it to the corresponding controller.
  • In MasterController.xib.designer.cs I can see that the connection is there. This is what MasterController.xib.designer.cs looks like:

    // Base type probably should be MonoTouch.UIKit.UIViewController or subclass [MonoTouch.Foundation.Register("AppDelegateBase")] public partial class AppDelegateBase {

        private MonoTouch.UIKit.UITabBarController __mt_oTabBarController;
        [MonoTouch.Foundation.Connect("oTabBarController")]
        private MonoTouch.UIKit.UITabBarController oTabBarController {
            get {
                this.__mt_oTabBarController = ((MonoTouch.UIKit.UITabBarController)(this.GetNativeField("oTabBarController")));
                return this.__mt_oTabBarController;
            }
            set {
                this.__mt_oTabBarController = value;
                this.SetNativeField("oTabBarController", value);
            }
        }
    }
    

But in my AppDelegatebase.cs, this.oTabBarController is always NULL. What is wrong here? The only difference to earlier projects is the fact that I have an additional XIB that contains a controller that I will use in the iPhone AND the iPad and therefore don't want to duplicate in the iPhones and the iPad's XIB.

Do I have to laod the MasterControll开发者_StackOverflow社区er.xib before I can do things to it? How? Puzzled.


There is no need to set the File's Owner to AppDelegateBase. Set it to the controller you want to use (in this case, a UITabBarController). In both MainWindowIPad.xib and MainWindowIPhone.xib, add a UITabBarController, connect it to an outlet in AppDelegate in each one and set its NIB Name field to MasterController.

What you have done so far is correct. But you also need to load the XIB that contains the controller you want displayed.

Since it is MasterController.xib the first one that will be loaded, set it as the app's main interface file in the project settings in MonoDevelop, under iPhone Application. Both "Main interface file" and "iPad interface file".

Don't forget to add the controller's view to a window. You can instantiate that through code, or just add it to the XIB and connect it to an outlet in your AppDelegateBase object.

If you want to load the XIB through code, consider the following snippet:

NSBundle.MainBundle.LoadNib ("MasterController", this, null);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜