Search code examples
appdelegateappkitinfo.plistxamarin.mac

Xamarin.Mac -- AppDelegate DidFinishLaunching -- Is the "Main Interface" specified in Info.plist already supposed to be loaded?


I have an existing .xib that needs to be displayed as the main page in a Xamarin.Mac application. If I set the "Main Interface" as this existing .xib, it does display but it's not done by the time my DidFinishLaunching override gets called. This is where I expect to do some initialization, but the outlets I specified are all null.

I am new to Xamarin and I'm trying to figure out if I need to override a different call that lets me know that the main page is done loading or if the issue lies elsewhere.

I did see that an NSWindowController has a WindowDidLoad override, but if I set the Main Interface in the info.plist, how does it know what the ViewController is for that view so that my override WindowDidLoad gets called?

I'm thinking I probably need to create the main window manually in DidFinishLaunching, but I can't find any documentation on how to create the main window through an .xib. There is documentation on how to get a storyboard from a nib, but I am not seeing anything on loading a .xib. If someone can find a good reference on how the main window gets initialize (with all the plumbing included) in a Xamarin.Mac application, that may be enough.

Thank you in advance for your time.


Solution

  • The chain of events is roughly:

    • Main invokes NSApplication.Main
    • Reads Info.plist to determine what xib/storyboard to load.
    • Storyboard is loaded and inflated. The view controller has a custom class that points to "ViewController"
    • Your ViewController is spun up, and WindowDidLoad get called.
    • DidFinishLaunching is not exactly what you are looking for.

    May I suggest take a look at the documentation in question to get a better understand of the full process:

    https://developer.xamarin.com/guides/mac/getting_started/hello,_mac/#Anatomy_of_a_Xamarin.Mac_Application