Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
i have an NSBox that is used as a dropbox... whenever something is dropped into the drop box i want the performDragOperation method to direct to anotherMethod in my App Controller class, but it doesn't work... i'm pretty sure i have everything linked correctly in IB, so i don't understand what's going on.

NSBox Class:
Code:
#import <Cocoa/Cocoa.h>
#import "AppController.h"

@interface DropBox : NSBox
	{
	IBOutlet AppController *appControllerRedirect;
	}
@end

--------------------------------------------------

#import "DropBox.h"
#import "AppController.h"

@implementation DropBox

//some drag and drop methods

- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
	{
        //some pasteboard stuff
	NSLog(@"item dropped in drop box"); [COLOR="SeaGreen"]//This gets called and displays In the console window, so i know the drag and drop methods within this class are coded correctly[/COLOR]
	[appControllerRedirect alertSound:nil];  [COLOR="Red"]//This doesn't get called.  why not??!![/COLOR]
        return YES;
	}

AppController Class:
Code:
#import <Cocoa/Cocoa.h>

@interface AppController : NSObject
        {

        }

- (IBAction)alertSound:(id)sender;

@end

--------------------------------------------------

#import "AppController.h"

@implementation AppController

- (IBAction)alertSound:(id)sender
	{
	NSBeep();
	}

i understand it is easy just to write NSBeep() in with the performDrapOperation method, but this isn't really my work – this is an example that illustrates my exact problem.

any help would be appreciated.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Use the debugger. Set a breakpoint and step through the code.

Or, just NSLog() the variable:
Code:
NSLog(@"appControllerRedirect: %@", appControllerRedirect);
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
would it matter if my drop box class is "Drop Box : NSBox" and not "Drop Box : NSObject"? i don't receive any warnings or errors, even after cleaning all... there must be something small i'm doing wrong here...
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
Here's A Small Example Project Of The Problem

attached is my XCode project with this very problem. it's very small. only necessary files are included concerning this problem. there is a main window class that holds the NSBox class. the NSBox class is used as the file validator using Aquatic Prime validation. finally there is an app controller class with a single method that beeps if the file being dropped is not valid.

also in the package is an invalid file (with specific extension) that can be used to test the drop box. everything is set up correctly (i think). once the user drops the invalid file into the drop box, aquatic prime will accept the file type, but will refuse the file, listing it as invalid in the console window. this is when it's also suppose to redirect to the method in the app controller class to NSBeep, but it does not get directed.

if anyone can open this up in XCode, build it, and take a look at the test project and help me understand what's going wrong that would be great.
 

Attachments

  • TestDropFile.zip
    60.3 KB · Views: 79

lucasgladding

macrumors 6502
Feb 16, 2007
319
1
Waterloo, Ontario
Found the problem...

Your main window controller is creating the box instead of it being unarchived from the Nib file. You can fix things two ways:

1:
Drop an NSBox into the window in the nib and specify its class as RegistrationDropBox. You then need to move the drag type registration from initWithFrame to awakeFromNib in your RegistrationDropBox class. Note: awakeFromNib is called instead of initWithFrame when objects are unarchived rather than created programatically. Finally, remove the box creation code from your main window controller. I have attached your source with these modifications. It sounds the beep when you drop the file.

2:
Create accessor methods for the appController instance variable inside the RegistrationDropBox class and set them in the window controller when you create the box. When you create an object programatically, you also need to set the outlets and variables programatically. This is why your original source was not working. The object defined in your nib is different from the one created in the window controller.

Looks good otherwise. Using an NSBox for drag and drop registration is a great idea.

Best of luck
 

Attachments

  • TestDropFile.zip
    75.1 KB · Views: 115
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.