Discussion:
Drag And Drop Killed By loadNibNamed
SD
2011-12-01 10:25:57 UTC
Permalink
Hello all, hope you can help.

My application loads a window from a nib and then displays it. This
window has a Text View (NSTextView in NSScrollView).

When the window is loaded from a nib using:

[NSBundle loadNibNamed:@"nibfilename" owner:m];


dropping text (using drag and drop) on the NSTextView doesn't work.

It doesn't seem to matter how I show the window once I load the nib.
Have it show via "Visible At Launch", show using
makeKeyAndOrderFront, show using beginSheet.

If I copy the window into my main nib show it, then drag and drop
works fine. Does anyone have any ideas why the drag and drop is
getting killed when I use loadNibNamed.

Thank you.
Alexander Reichstadt
2011-12-01 11:42:49 UTC
Permalink
I remember to have run into the same problem. Somehow the window was not present early enough. I ended up using NSWindowController's

[[yourwindowcontrollersubclass alloc] initWithWindowNibName:@"YourNibNameWithoutExtensionNib"]

which worked.
Post by SD
Hello all, hope you can help.
My application loads a window from a nib and then displays it. This window has a Text View (NSTextView in NSScrollView).
dropping text (using drag and drop) on the NSTextView doesn't work.
It doesn't seem to matter how I show the window once I load the nib. Have it show via "Visible At Launch", show using makeKeyAndOrderFront, show using beginSheet.
If I copy the window into my main nib show it, then drag and drop works fine. Does anyone have any ideas why the drag and drop is getting killed when I use loadNibNamed.
Thank you.
_______________________________________________
MacOSX-dev mailing list
http://www.omnigroup.com/mailman/listinfo/macosx-dev
Christiaan Hofman
2011-12-01 12:12:07 UTC
Permalink
Post by Alexander Reichstadt
I remember to have run into the same problem. Somehow the window was not present early enough. I ended up using NSWindowController's
which worked.
Post by SD
Hello all, hope you can help.
My application loads a window from a nib and then displays it. This window has a Text View (NSTextView in NSScrollView).
dropping text (using drag and drop) on the NSTextView doesn't work.
It doesn't seem to matter how I show the window once I load the nib. Have it show via "Visible At Launch", show using makeKeyAndOrderFront, show using beginSheet.
If I copy the window into my main nib show it, then drag and drop works fine. Does anyone have any ideas why the drag and drop is getting killed when I use loadNibNamed.
Thank you.
I cannot tell you why you experience this problem. For one, I think you are leaving out the crucial information about why this happens. I expect, but have no way of knowing, that this may be a timing issue, so you may be showing the window too early in the process. Have you tried loading at (much) different times? It seems that there is a problem with registering drag types, so have you actually checked those? You certainly should check all those things and more.

As a general matter, you should (almost) always use one of the four nib loading classes (or subclasses) NSWindowController, NSViewController, NSDocument, or NSApplication to do the loading for you. It does what you do plus some more things that you (and I) don't know about but that can be important (for instance binding-to-owner bugs). You should have very good reasons to side step that. Moreover, you should be pretty knowledgable and experienced to know lots of difficult pitfalls to avoid (like this ones) before you should embark on doing your own nib loading. I must say that from your post I don't get the impression you are sufficiently qualified or have good enough reasons. So my strong advice is simply: don't do this.

Christiaan
SD
2011-12-02 01:55:43 UTC
Permalink
Subclassing and using NSWindowController worked, thank you.

Specifically:
MyNSWindowController *m = [[[MyNSWindowController alloc]
initWithWindowNibName:@"myNib"] autorelease];
[m window];

SD

______________________________________________________________________
Previous message on 12/1/11 at 12:42 PM +0100
**********************************************************************
Post by Alexander Reichstadt
I remember to have run into the same problem. Somehow the window was
not present early enough. I ended up using NSWindowController's
[[yourwindowcontrollersubclass
which worked.
Post by SD
Hello all, hope you can help.
My application loads a window from a nib and then displays it.
This window has a Text View (NSTextView in NSScrollView).
dropping text (using drag and drop) on the NSTextView doesn't work.
It doesn't seem to matter how I show the window once I load the
nib. Have it show via "Visible At Launch", show using
makeKeyAndOrderFront, show using beginSheet.
If I copy the window into my main nib show it, then drag and drop
works fine. Does anyone have any ideas why the drag and drop is
getting killed when I use loadNibNamed.
Thank you.
_______________________________________________
MacOSX-dev mailing list
http://www.omnigroup.com/mailman/listinfo/macosx-dev
Loading...