How do I use a subclass of NSDocumentController in XCode 4?

前端 未结 7 1440
陌清茗
陌清茗 2020-12-31 11:34

I am currently in the process of trying to teach myself Cocoa development. Toward this end, I purchased a mostly-excellent book, Cocoa Recipes for Mac OS X: Vermont Reci

7条回答
  •  耶瑟儿~
    2020-12-31 11:46

    The answer marked correct (@Bavarious'answer) fails to work on document-based apps because documents often load before any applicationWillFinishLaunching: is called. After reading the helpful clues in @Graham Perks answer, I tried a few different approaches and this seems to work reliably:

    @implementation AppDelegate
    
    - (id)init
    {
        self = [super init];
        if (self) {
            MyDocumentController *dc = [[MyDocumentController alloc] init];
            if (dc) {};
        }
        return self;
    }
    

    Note Obviously (if not already created) you'll need to create an AppDelegate yourself first and link it in your MainMenu.XIB.

提交回复
热议问题