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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:36:46+00:00 2026-05-27T01:36:46+00:00

I have a view based table with a custom cell view. Inside this custom

  • 0

I have a view based table with a custom cell view. Inside this custom cell view, I have a custom NSButton that acts like a check box (it toggles a custom image on and off). This part works well. The images toggle on and off perfectly.

What I want to do is associate the custom button in the row with the actual row in the table. When I check/click the button it will highlight the the corresponding row and then perform an action on the row in which the check box/ button is situated. For example, removing the row from the table when the NSButton is clicked.

My custom NSButton is implemented as follows:

Header file:

#import <Foundation/Foundation.h>

@interface CustomCheckButton : NSButton {
    BOOL _checked;
}

@property (nonatomic, setter=setChecked:) BOOL checked;

-(void) setChecked:(BOOL) check;
@end

Implementation:

#import "CustomCheckButton.h"

@implementation CustomCheckButton

@synthesize checked = _checked;

-(id) init
{
    if( self=[super init] )
    {
        self.checked = NO;
        [self setTarget:self];
        [self setAction:@selector(onCheck:)];
    }
    return self;
}

-(void) awakeFromNib
{
    self.checked = NO;
    [self setTarget:self];
    [self setAction:@selector(onCheck:)];
}

-(void) setChecked:(BOOL) check
{
    _checked = check;
    if( _checked )
    {
        NSImage* img = [NSImage imageNamed:@"check_on.png"];
        [self setImage:img];
        [self setState:NSOnState];
    }
    else
    {
        NSImage* img = [NSImage imageNamed:@"check_off.png"];
        [self setImage:img];
        [self setState:NSOffState];
    }
}

-(void) onCheck:(id) sender
{
    self.checked = !_checked;
    NSLog(@"A check box was pressed");
}

@end

The current solution does not associate the button with the row at all. When I sort the rows, for example, the selected image is not linked to the row and often stays in the same place within the table, even though a different row was selected.

Any help on this would be greatly appreciated.

  • 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-27T01:36:47+00:00Added an answer on May 27, 2026 at 1:36 am

    How about adding a delegate field and setting it with a custom initializer? Or you could add it as a property and set it after calling alloc init. This can be done in 2 ways: via IB or programmatically.

    If you want to do it programmatically, you’ll need to do a couple of things:

    So let’s look at the class that has a UITableView element in it. Assuming this class is also the UITableViewDelegate and UITableViewDataSource, it will have to have an implementation of the data source method

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
    

    which returns a cell at a given indexPath. Here, you could instantiate your custom cell and in that, add a custom button and set it’s delegate to the cell itself, by adding this to your code:

    in CustomCheckButton.h:

    UITableViewCell * delegate;
    //...
    @property (nonatomic, assign) UITableViewCell * delegate;
    

    in CustomCheckButton.m

    @synthesize delegate;
    

    in the table view data source method:

    // initialize my custom cell element, assume it has a property for a CustomCheckButton with name checkButton
    // ... some code
    myCell.checkButton.delegate = mycell; // link the button's delegate to the cell
    // ... some other code, probably based on indexPath
    return myCell;
    

    This might seem like a big task, but you can do it in interface builder too, assuming you have a xib for your custom cell class. If you do, just open the xib. You’ll probably have a button on it already; change it’s class to your own CustomCheckButton and you’ll be able to set its delegate property like you would normally, with ctrl-drag from the button to the cell.

    Hope this helps!

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

Sidebar

Related Questions

I have a nib-based table view cell which I created in Interface builder. I
I have a custom table cell, right now, it's all Nib based. When I
I have a view based app that works well. (In other words, I'm not
I have a split view-based app that presents a master-detail interface, and uses a
I have a view-based NSTableView populated custom NSTabelCellView subclass, which are the lowest objects
I have a view-based app that just does one thing : show a array
I have created split view based ipad app, where master view is table view
I have a table based app and would like to add a tab bar
I have a foreach based table in my MVC partial view: <% foreach (var
I have text fields inside a custom view inside an NSOutlineView . Editing one

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.