Re: IB problem with object hierarchy
Re: IB problem with object hierarchy
- Subject: Re: IB problem with object hierarchy
- From: Chris Giordano <email@hidden>
- Date: Sat, 14 Dec 2002 15:10:47 -0500
Beat,
I'm not 100% sure of the answer to why what you've done doesn't work.
The only thing that I can think of is that it might have to do with the
order in which things are drawn. I know from past experience that if
you have two things that overlap, whichever one is drawn last will be
drawn on top (not rocket science there) -- if your application is
drawing the image after the text fields, since they are on the same
level, the image would be overwriting the text fields.
However, despite not having an answer, I do have a solution. It is
much like the one you found in the archive. Since I had some time, I
tried building a quick project, and I could get it to do what you want,
namely, draw an image behind some text fields (and pop up buttons and
other buttons, just for good measure).
I put various fields and whatnot into a window. Then, after selecting
them, I made them all subviews of a custom view (Layout > Make subviews
of > Custom View). Then, I changed the class of the custom view to
NSImageView.
I also instantiated in my nib an NSObject subclass, AppDelegate, that
had one connection to the NSImageView that contained the various fields
and whatnot. In the AppDelegate's awakeFromNib method, I had the
following:
[myImageView setImage:[[NSImage alloc]
initWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"20021204-4" ofType:@"jpg"]]];
I obviously also had an image named "20021204-4.jpg" in my
application's bundle. The end result was an image with some text
fields and other controls drawn on top of it.
So, it looks like you should be able to do what you want.
chris
On Friday, December 13, 2002, at 04:07 AM, Beat Koch wrote:
In have added a custom view to my nib-file. On that custom view, I
have put an NSImageView which is as large as the view; it should
display a background image. On top of the image, I've put several text
fields. In design mode, everything looks fine, but in test mode or
when the application is run, the image always hides the text fields.
Sending the image to the back does not help.
I have extracted the hierarchy of the nib-file with nibtool (see
below) and as expected, the NSImageView is on the same level as the
text fields, which probably is the reason for having this problem. The
question is: how can I force the NSImageView to become the parent
object for the text fields? Everything works well if I put the image
view and text fields on a window, but not if I put them on a custom
view.
Just before sending this mail, I've found a solution proposed by Ivan
Myrvold (http://cocoa.mamasam.com/COCOADEV/2002/05/2/34620.php):
Selecting everything in the view and making it the subview of a box
works for me, too. But why does this work? In the object hierarchy,
the image view is still on the same level as the text fields, so it
seems to be a coincidence that this produces the correct results.
Regards, Beat
Hierarchy = {
"Object 1 <NSCustomObject> (File's Owner)" = {
"Object -1 <IBFirstResponder> (First Responder)";
"Object 5 <NSCustomView> (MyView)" = {
"Object 239 <NSTextField> (NSTextField9)";
"Object 240 <NSTextField> (NSTextField3)";
"Object 313 <NSImageView>";
};
"Object 13 <NSWindowTemplate> (Window)" = {
"Object 14 <NSView>" = {
"Object 95 <NSTextField> (NSTextField23)";
"Object 130 <NSButton> (NSButton)";
};
};
};
}; /* End Hierarchy */
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.