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 810581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:54:32+00:00 2026-05-15T00:54:32+00:00

I have an NSCollectionView and the view is an NSBox with a label and

  • 0

I have an NSCollectionView and the view is an NSBox with a label and an NSButton. I want a double click or a click of the NSButton to tell the controller to perform an action with the represented object of the NSCollectionViewItem. The Item View is has been subclassed, the code is as follows:

#import <Cocoa/Cocoa.h>
#import "WizardItem.h"

@interface WizardItemView : NSBox {
    id delegate;
    IBOutlet NSCollectionViewItem * viewItem;
    WizardItem * wizardItem;
}

@property(readwrite,retain) WizardItem * wizardItem;
@property(readwrite,retain) id delegate;

-(IBAction)start:(id)sender;

@end

#import "WizardItemView.h"

@implementation WizardItemView
@synthesize wizardItem, delegate;

-(void)awakeFromNib {   
    [self bind:@"wizardItem" toObject:viewItem withKeyPath:@"representedObject" options:nil];
}

-(void)mouseDown:(NSEvent *)event {
    [super mouseDown:event];
    if([event clickCount] > 1) {
        [delegate performAction:[wizardItem action]];
    }   
}

-(IBAction)start:(id)sender {
    [delegate performAction:[wizardItem action]];
}


@end

The problem I’ve run into is that as an IBAction, the only things in the scope of -start are the things that have been bound in IB, so delegate and viewItem. This means that I cannot get at the represented object to send it to the delegate.

Is there a way around this limited scope or a better way or getting hold of the represented object?

Thanks.

  • 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-05-15T00:54:33+00:00Added an answer on May 15, 2026 at 12:54 am

    Firstly, you almost never need to subclass views.

    Bind doesn’t do what you think – you want addObserver:forKeyPath:options:context: (You should try to understand what -bind is for tho ).

    When you say “the key seems to be it being the “prototype” view for an NSCollectionViewItem” I think you are really confused…

    Forget IBOutlet & IBAction – they don’t mean anything if you are not Interface Builder. “Prototype” means nothing in Objective-c.

    The two methods in the view do not have different scope in any way – there is no difference between them at all. They are both methods, equivalent in every way apart from their names (and of course the code they contain).

    If wizardItem is null in -start but has a value in -mouseDown this is wholly to do with the timing that they are called. You either have an object that is going away too soon or isn’t yet created at a point you think it is.

    Are you familiar with NSZombie? You will find it very useful.

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

Sidebar

Related Questions

I have a button that is inside a view repeated inside a NSCollectionView. I
I have a NSCollectionView , that displays some files: What I want is... being
I have a list view class that just like NSCollectionView requires an additional prototype
I have an NSCollectionView that contains a collection of CustomViews . Initially it tiled
In my setup I have an NSCollectionView of volumes connected to the mac. For
I have a working NSCollectionView with one minor, but critical, exception. Getting and highlighting
I have a basic Cocoa app with a custom NSCollectionView that overrides drawRect: to
have written this little class, which generates a UUID every time an object of
Have deployed numerous report parts which reference the same view however one of them
I'm developing a Cocoa application and want to be able to click a button

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.