NIB Files + Views. Is it a good practice?

  • Hello all.

    I was playing a bit with instantiating new views in a NIB file.
    What I do is the following:

    1) I create a subclass V of NSView
    2) I instantiate V
    3) I populate the instance with controls using the palette
    4) I use the instance by referencing it in the AppController

    However, I realized that I don't need any additional functionality for
    the View when doing what I have described. NSView would be fine. So
    having the subclass V is useless.

    What I did was the following:

    1) I create a subclass V of NSView
    2) I instantiate V
    3) I populate the instance with controls using the palette
    4) I set back the custom class of the instance to NSView
    5) I deleted V from the NIB classes
    6) I use the instance of the view by referencing it in the AppController

    Everything worked well so I suppose that this is a good way to do.
    Moreover I have also seen some NIBs with instances of View components
    but no NSView subclasses inside them.

    So the question is: is this a good practice? And if yes, why can't I
    instantiate directly a NSView instead of creating a subclass just for
    deleting it after the View instance creation?

    Thank you,
    Fabio
  • Hi,

    It sounds like you haven't noticed the 'Custom View' item on the
    'Cocoa-Containers' palette, it's a basic NSView instance.

    Wain

    On 21 Oct 2006, at 17:47, Fabio Mancinelli wrote:

    > Hello all.
    >
    > I was playing a bit with instantiating new views in a NIB file.
    > What I do is the following:
    >
    > 1) I create a subclass V of NSView
    > 2) I instantiate V
    > 3) I populate the instance with controls using the palette
    > 4) I use the instance by referencing it in the AppController
    >
    > However, I realized that I don't need any additional functionality
    > for the View when doing what I have described. NSView would be
    > fine. So having the subclass V is useless.
    >
    > What I did was the following:
    >
    > 1) I create a subclass V of NSView
    > 2) I instantiate V
    > 3) I populate the instance with controls using the palette
    > 4) I set back the custom class of the instance to NSView
    > 5) I deleted V from the NIB classes
    > 6) I use the instance of the view by referencing it in the
    > AppController
    >
    > Everything worked well so I suppose that this is a good way to do.
    > Moreover I have also seen some NIBs with instances of View
    > components but no NSView subclasses inside them.
    >
    > So the question is: is this a good practice? And if yes, why can't
    > I instantiate directly a NSView instead of creating a subclass just
    > for deleting it after the View instance creation?
    >
    > Thank you,
    > Fabio
  • Wain wrote:
    > Hi,
    >
    > It sounds like you haven't noticed the 'Custom View' item on the
    > 'Cocoa-Containers' palette, it's a basic NSView instance.
    >
    > Wain
    >

    Well actually I have noticed it and I use it.
    Here it is a screenshot of my application:
    http://img221.imageshack.us/img221/600/picture1eg8.png

    What it does is very straightforward... By clicking on the buttons it
    replaces the content of the CustomView with View1 or View2.

    My question focused on how to create View1 and View2 instances.

    What CustomView has to do with them?

    Thank you.
    Fabio
  • Hi!
    If you don't need additional functionality, you may just drag a custom
    view to your nib file, than select it, place any controls on it, and
    connect it to your controller.
    If you want two similar views, you may duplicate the first and connect
    it to your controller.
    I believe it is a good practise.
    What is your problem?

    Yours,
    Damian/Three-eyed Fish

    On Oct 22, 2006, at 16:18, Fabio Mancinelli wrote:

    > Wain wrote:
    >> Hi,
    >> It sounds like you haven't noticed the 'Custom View' item on the
    >> 'Cocoa-Containers' palette, it's a basic NSView instance.
    >> Wain
    >
    > Well actually I have noticed it and I use it.
    > Here it is a screenshot of my application:
    > http://img221.imageshack.us/img221/600/picture1eg8.png
    >
    > What it does is very straightforward... By clicking on the buttons it
    > replaces the content of the CustomView with View1 or View2.
    >
    > My question focused on how to create View1 and View2 instances.
    >
    > What CustomView has to do with them?
    >
    > Thank you.
    > Fabio
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/
    > <threeeyedfish...>
    >
    > This email sent to <threeeyedfish...>
    >
  • You can drag a custom view from the palette into where view1 and
    view2 are now.

    Mike.

    On 22 Oct 2006, at 13:18, Fabio Mancinelli wrote:

    > Wain wrote:
    >> Hi,
    >> It sounds like you haven't noticed the 'Custom View' item on the
    >> 'Cocoa-Containers' palette, it's a basic NSView instance.
    >> Wain
    >
    > Well actually I have noticed it and I use it.
    > Here it is a screenshot of my application: http://
    > img221.imageshack.us/img221/600/picture1eg8.png
    >
    > What it does is very straightforward... By clicking on the buttons
    > it replaces the content of the CustomView with View1 or View2.
    >
    > My question focused on how to create View1 and View2 instances.
    >
    > What CustomView has to do with them?
    >
    > Thank you.
    > Fabio
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/mike.abdullah%
    > 40gmail.com
    >
    > This email sent to <mike.abdullah...>
  • > My question focused on how to create View1 and View2 instances.
    >
    > What CustomView has to do with them?

    Drag a custom view into your window, position and size it. Then in the
    Inspector, choose Custom Class, and choose your custom class. Now when the
    nib is loaded your view will be created.

    --
    Scott Ribe
    <scott_ribe...>
    http://www.killerbytes.com/
    (303) 722-0567 voice
  • on 10/22/06 6:18 AM, <xenon...> purportedly said:

    > Well actually I have noticed it and I use it.
    > Here it is a screenshot of my application:
    > http://img221.imageshack.us/img221/600/picture1eg8.png
    >
    > What it does is very straightforward... By clicking on the buttons it
    > replaces the content of the CustomView with View1 or View2.
    >
    > My question focused on how to create View1 and View2 instances.
    >
    > What CustomView has to do with them?

    If I understand you correctly, you want to "swap" out one NSView object for
    another, at the click of a button? If so, this is only something that can be
    done entirely in code AFAIK. You'll have to leave IB out of the picture. But
    it's probably the harder way to do the job.

    I see two possible alternatives:

    1. Maintain the view "content" in a separate model objects. By "content" I
    mean what is actually *drawn* into the view, and not the view object itself.
    All the button(s) do is tell the view to draw the content from the model
    they are linked to.

    2. Create a tabless, borderless NSTabView. Put each view in each "pane", use
    the buttons to switch tabs.

    Best,

    Keary Suska
    Esoteritech, Inc.
    "Demystifying technology for your home or business"
  • Keary Suska wrote:
    > on 10/22/06 6:18 AM, <xenon...> purportedly said:
    >
    >> Well actually I have noticed it and I use it.
    >> Here it is a screenshot of my application:
    >> http://img221.imageshack.us/img221/600/picture1eg8.png
    >>
    >> What it does is very straightforward... By clicking on the buttons it
    >> replaces the content of the CustomView with View1 or View2.
    >>
    >> My question focused on how to create View1 and View2 instances.
    >>
    >> What CustomView has to do with them?
    >
    > If I understand you correctly, you want to "swap" out one NSView object for
    > another, at the click of a button? If so, this is only something that can be
    > done entirely in code AFAIK. You'll have to leave IB out of the picture. But
    > it's probably the harder way to do the job.
    >

    Well actually the code I wrote was just to experiment... I don't want to
    do any swapping like that in a real world case :)
    I was just playing with View instances in a NIB file and I had some
    doubts on how they were actually created.

    It turned out that I simply ignored that a CustomView could be dragged
    from the palette directly to the NIB file :)

    Thank you
  • Thank you all for your answers.
    It turned out that I simply ignored that a CustomView could be dragged
    directly to the NIB file :)
previous month october 2006 next month
MTWTFSS
            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          
Go to today