Re: create a view without IB
Re: create a view without IB
- Subject: Re: create a view without IB
- From: Shawn Erickson <email@hidden>
- Date: Mon, 19 Dec 2005 17:12:57 -0800
On 12/19/05, Andrea Salomoni <email@hidden> wrote:
>
Hi and thank you,
>
>
The problem is this:
>
>
I have a nstabview created with ib and correctly connected.
>
When I click a certain button I would like to add a nstabviewitem
>
(already done) and put inside it a nstextview.
>
To do it I made a new nib file with IB, created a class and put
>
inside this view the textfiled.
>
Now, there isn't any problem when I instatiate this object with IB
>
using the placeholder outlet, but when I need to create the
>
placeholer (or better a new nsview object) starts the problems...
>
As you can see in my code:
>
>
// setting up interface
>
theChatView = [[privateChat alloc]init];
>
Create the object that contains nstextview
>
[[theChatView mainView] setFrame:[placeholder bounds]];
>
here I have to create the placeholder in other way... don't know how
>
maybe
>
NSView * newPlaceholder = [[NSView alloc]initWithFrame:.....];
>
[[theChatView mainView] setFrameOrigin:NSZeroPoint];
>
[placeholder addSubview:[theChatView mainView]];
>
[_allMyViews addObject:theChatView];
>
[privateChat release];
>
>
This is my doubt..
Sorry I am not following what exactly you are doing (the code snippet
above has very little context with it to help us understand what is
what) but...
1) You have a tab view that you want to add additional tabs to at runtime.
2) The tab view exists in a window that exists in a nib file.
You can add tabs at runtime to an existing NSTabView using
addTabViewItem: or insertTabViewItem:atIndex. These methods require
you to supply an NSTabViewItem instance that represents the panel you
are adding. At runtime you create NSTabViewItem using
initWithIdentifier: (the identifier object is for use to help in
identifying the tab). It appears that you understand this much.
The next issue issue adding a view (or hierarchy of views) into the
NSTabViewItem. You can either programmatically create the views needed
(initWithFrame:, etc.) or could load a predefined view hierarchy from
an already loaded nib or a secondary nib.
If you use a nib then you should be calling init on any view since the
nib contain the instances you need, you don't need to create them just
get a hold of them. To get at them you would use an IBOutlet in the
code and connect that up with the view in your nib. In the case of a
secondary nib you likely would make the file owner of the nib the
class that contains the IBOutlet you want to use.
It is really hard to explain this in email so I will stop now... I
strongly suggest finding a good book on Cocoa development (search the
archives and amazon for such books).
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden