Document Based

Discussion in 'Mac Programming' started by davidlt, Jun 30, 2008.

  1. macrumors member

    Joined:
    May 22, 2007
    Location:
    Lithuania
    #1
    Hi, I can't figure out this.
    I have MyDocument class which inherits from NSDocument and DocView which intherits from NSView. DocView has IBOutlet to MyDocument. When I working inside DocView and I want to get some information from my MyDocument object, I get "null".

    DocView.h:
    MyDocument.h
    And let's say code in DocView will be like this:
    So I launch my application, press File, Open, I will choose my last saved file, MyDocument becomes initialized and it's time to initialize docView and it should write "Rand: YES" into the Log (rand always gives YES in this example), but I get "Rand: (null)". So why can't I contact my MyDocument?

    In Interfeice Builder there is connection from CustomView (DocView) to File's Ower (MyDocument).
     
  2. macrumors regular

    Joined:
    Apr 7, 2004
    Location:
    Israel
    #2
    I believe the nib loader first fully initializes all custom view objects archived in a nib before setting their outlets and other instance variables.

    This would mean that your custom view doesn't yet have its outlet to MyDocument set inside its initializer. Which is where you are trying to use it, thus resulting in NULL.

    Note, this should only be happening with custom views. Other objects are already initialized before ever being archived into the nib.

    I may be wrong though.
     
  3. thread starter macrumors member

    Joined:
    May 22, 2007
    Location:
    Lithuania
    #3

Share This Page