Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8528563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:49:44+00:00 2026-06-11T08:49:44+00:00

I have an NSImageView subclass that I use for dragging and dropping Files onto

  • 0

I have an NSImageView subclass that I use for dragging and dropping Files onto in my app.

To do this I created a subclass of NSImageView and also dragged the NSImageView onto my XIB, I then set the class of the XIB NSImageView Object to my custom subclass.

Everything works well with the drag and drop and I know I have the correct file after the drag.

The problem comes in when I want to update a textfield on the MainViewController based on the file dragged in.

I created the following subclass and protocol

#import <Cocoa/Cocoa.h>
#import <Quartz/Quartz.h>

@protocol PDFDraggedIntoWell <NSObject>
@required
-(void)PDFDraggedIntoWellWithURL:(NSURL*) importedURL;

@end


@interface DragAndDropImageView : NSImageView

@property (strong) id <PDFDraggedIntoWell> delegate;

@end

Then in my implementation in the subclass I try to call the delegate method

-(void) finishedDragginInFileWithURL:(NSURL*) importedURL{
    if( self.delegate != nil && [ self.delegate respondsToSelector: @selector(PDFDraggedIntoWellWithURL:)]) {
        [self.delegate performSelector:@selector(PDFDraggedIntoWellWithURL:) withObject:importedURL];
    }
}

The problem I run into is how do you assign the delegate. From the XIB NSImageView to my MainviewController I connect up an IBOutlet

@property (weak) IBOutlet DragAndDropImageView *draggedFileImageView;

And I have declared that my ViewController will receive the delegate

@interface MyMainUIViewController ()<PDFDraggedIntoWell>

with the appropriate method implemented

-(void) PDFDraggedIntoWellWithURL:(NSURL *)importedURL{   }

Now I have tried in various places to assign delegate to self (in viewDidLoad – which doesn’t get called since the view is being loaded in a XIB??) and also in

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

but all I get back is the delegate is still nil when debugging.

What am I doing wrong? Thanks for the help!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:49:45+00:00Added an answer on June 11, 2026 at 8:49 am

    If you are using xibx the initWithCoder method is called for initialization. Set your delegate there.

    - (id)initWithCoder:(NSCoder *)aDecoder {
        self = [super initWithCoder:aDecoder];
        if (self) {
            UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
            myView.delegate = self;
        }
        return self;
    }
    

    Alternatively set the delegate via interface builder by dragging wile holding ctrl from the File’s Owner to your view. Like this:
    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have an app that can use tts to read text messages. It can also
Let's say I have an NSImage that's 100x100. I also have an NSImageView that's
I have created a subclass of NSImageView- let's call it MyView- and have added
I have created a class derived from NSImageView. However, the classes's constructor (init) is
I have a NSTableView that holds a name to all of my NSImageView's, and
I have an NSWindow containing and NSImageView. I want that the user can drag
I have a NSCollectionView , that displays some files: What I want is... being
I have an NSImageView that needs to redraw a constantly updating image. I have
I have an NSWindow which contains an NSImageView. This window gets activated everytime I
I have requirement like this, Have One NSIMageView and which will be changing frequently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.