Professional Web Applications Themes

Initializing NSViews (in doents) - Mac Programming

Until now I've let the NSView subclasses be initialized via awakeFromNib, and that has worked well. But now I'm working on a doent-based app where the doc window has two views; one for a subclass of NSView (which is also the root class of the data tree that makes up the doent) and one for an NSTableView, which is an outlet for the NView subclass. The NSView subclass itself is displayed in an NSScrollView, and it is initialized by awakeFromNib. This app works fine the way it is until I try loading a saved doent. What happens then is the ...

  1. #1

    Default Initializing NSViews (in doents)

    Until now I've let the NSView subclasses be initialized via
    awakeFromNib, and that has worked well. But now I'm working on a
    doent-based app where the doc window has two views; one for a
    subclass of NSView (which is also the root class of the data tree that
    makes up the doent) and one for an NSTableView, which is an outlet
    for the NView subclass. The NSView subclass itself is displayed in an
    NSScrollView, and it is initialized by awakeFromNib.

    This app works fine the way it is until I try loading a saved
    doent. What happens then is the following:

    - A new doent is initialized, and with it the doent window and a
    new instance of the NSView subclass.
    - loadDataRepresentation: releases the first instance of the NSView
    subclass and loads the saved version. As far as I can tell it loads
    correctly.
    - awakeFromNib initializes a new instance of the NSView subclass, and
    the instance that was loaded floats in in limbo. I can access it but
    it won't be displayed.

    So what is the correct way to initialize an instance of NSView in a
    doent?

    --
    C Lund, www.notam02.no/~clund
    C Guest

  2. #2

    Default Re: Initializing NSViews (in doents)

    C Lund <no> wrote:
     

    Why is any instance of the NSView subclass being "loaded"? An NSView
    isn't data. Your doent (the stuff you load off disk when the user
    says Open) should consist of just data (the M in MVC). The NSView in the
    window should come from the nib (the V in MVC). When the window appears,
    you tell the view to do whatever it needs to do in order to display the
    data (the C in MVC). m.

    --
    matt neuburg, phd = com, http://www.tidbits.com/matt/
    Read TidBITS! It's free and smart. http://www.tidbits.com
    matt Guest

  3. #3

    Default Re: Initializing NSViews (in doents)

    C Lund <no> wrote:
     

    That all depends. You could do it IB, along with the rest of your
    doent window. Drag your NSView subclass's .h file out of PB to the
    nib file in IB, and then drag a 'CustomView' from the palette to the
    doent window. Make sure the CustomView is selected, go to Custom
    Class on the inspector, and select your NSView subclass.

    Now hook up the outlets and actions and all that, and you're set.
    Paul Guest

  4. #4

    Default Re: Initializing NSViews (in doents)

    In article <1g45h7t.7t0oixg14y80N%com>,
    com (matt neuburg) wrote:
     

    So an NSView should only be initialized once, and from then on I only
    change the content? Seems I was trying to do too much with too few
    classes...

    --
    C Lund, www.notam02.no/~clund
    C Guest

  5. #5

    Default Re: Initializing NSViews (in doents)

    In article <chello.com>,
    C Lund <no> wrote:
     
    >
    > So an NSView should only be initialized once, and from then on I only
    > change the content? Seems I was trying to do too much with too few
    > classes...[/ref]

    I don't know how your program is designed, but you should always at
    least try to follow MVC. (If you already know about all this, just skip
    this message....) M means Model, this is stuff that actually stores
    data. This is what you would think of as 'the doent', and this is
    what would get saved out to disk. V means View, which is what actually
    puts the M on the screen. These are normally NSView subclasses, either
    custom subclasses or regular Cocoa classes like NSTextView or
    NSPopupButton. C measn Controller, which hooks the two together. The
    basic idea is that your View shouldn't necessarily know the exact
    structure of the Model, and the Model shouldn't know the exact structure
    of the View. The Controller exists to hook the M and V together. This
    makes changes a lot easier, and it also makes reuse easier. Long story
    short, you should never store actual doent data in your NSView
    subclasses, they should ask the Controller for info which in turn gets
    it from the Model. This separation of concerns tends to make life easier
    in a number of different ways.
    Michael Guest

  6. #6

    Default Re: Initializing NSViews (in doents)

    In article <mail-C6D908.11071110112003localhost>,
    Michael Ash <com> wrote:
     
    >
    > I don't know how your program is designed, but you should always at
    > least try to follow MVC. (If you already know about all this, just skip
    > this message....) M means Model, this is stuff that actually stores
    > data. This is what you would think of as 'the doent', and this is
    > what would get saved out to disk. V means View, which is what actually
    > puts the M on the screen. These are normally NSView subclasses, either
    > custom subclasses or regular Cocoa classes like NSTextView or
    > NSPopupButton. C measn Controller, which hooks the two together. The
    > basic idea is that your View shouldn't necessarily know the exact
    > structure of the Model, and the Model shouldn't know the exact structure
    > of the View. The Controller exists to hook the M and V together. This
    > makes changes a lot easier, and it also makes reuse easier. Long story
    > short, you should never store actual doent data in your NSView
    > subclasses, they should ask the Controller for info which in turn gets
    > it from the Model. This separation of concerns tends to make life easier
    > in a number of different ways.[/ref]

    Yeah, that's probably where I went wrong.

    --
    C Lund, www.notam02.no/~clund
    C Guest

Similar Threads

  1. CFTREE not initializing
    By pdrich in forum Macromedia ColdFusion
    Replies: 1
    Last Post: March 31st, 06:28 PM
  2. Coverting Indesign 2.0 doents to Microsoft Word xp doents
    By Pam_Sepesi@adobeforums.com in forum Adobe Indesign Windows
    Replies: 3
    Last Post: May 3rd, 02:43 AM
  3. Desperate to convert Word doents into PDF doents
    By R_Vaughan@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 17
    Last Post: April 19th, 06:24 PM
  4. message passing via NSViews w/o actual Cocoa calls
    By matt in forum Mac Programming
    Replies: 3
    Last Post: August 14th, 12:07 AM
  5. Initializing ksh variables
    By Chris Vidal in forum Sun Solaris
    Replies: 0
    Last Post: July 8th, 07:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139