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

  • Home
  • SEARCH
  • 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 6591699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:27:31+00:00 2026-05-25T17:27:31+00:00

After adding a NSTableView to my xib on Xcode 4 I set it to

  • 0

After adding a NSTableView to my xib on Xcode 4 I set it to have 4 columns. The 1st column is a simple column that will contain the name of an item. The other 3 are checkboxes. I dragged a Check Box Cell from the object library to the tableview.

I populate the table and the checkboxes get created and shown, however if I click on the nothing happens, I can’t check or uncheck them. Furthermore, I don’t even know how to do it by code.

How can I make this work: be able to check or uncheck the checkboxes and get their states from code.

I already saw this question and it didn’t really answer my question.

Here is some of the code to take care of table, as requested:

- (int)numberOfRowsInTableView:(NSTableView *)tableView
{
    return (int)[myArray count];
}

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
{
    if([[tableColumn identifier] isEqualToString:@"col1"])
    {
       return[NSNumber numberWithInt:NSOffState];
    }    

    return [myArray objectAtIndex:row];
}

- (void)tableView:(NSTableView *)tableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    NSLog(@"%d", [anObject boolValue]);
    if([[tableColumn identifier] isEqualToString:@"col1"])
    {
        NSLog(@"click col1");
    }        
    if([[tableColumn identifier] isEqualToString:@"col2"])
    {
        NSLog(@"click col2");
    }        

}

I just added more code. How do I set it to check/uncheck?

  • 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-25T17:27:32+00:00Added an answer on May 25, 2026 at 5:27 pm

    The model

    You need to decide upon a model, i.e., how you’re going to represent the data that’s being shown on the table view. For example:

    // SomeObject.h
    #import <Foundation/Foundation.h>
    @interface SomeObject
    @property (copy) NSString *name;
    @property (assign,getter=isVisible) BOOL visible;
    @property (assign,getter=isOpaque) BOOL opaque;
    @property (assign,getter=isAnimatable) BOOL animatable;
    @end
    
    // SomeObject.m
    #import "SomeObject.h"
    @implementation SomeObject
    @synthesize name, visible, opaque, animatable;
    - (void)dealloc {
        [name release];
        [super dealloc];
    }
    @end
    

    The nib file

    For the sake of this answer, give the table columns identifiers that match the property names in SomeObject.

    Providing values from the model to the table view

    - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
    {
        // Retrieve the model object corresponding to `row'
        SomeObject *obj = [myArray objectAtIndex:row];
    
        // Return the object property corresponding to the column
        if([[tableColumn identifier] isEqualToString:@"name"])
        {
            return obj.name;
        }
        // Since this method has return type `id', we need to box the
        // boolean values inside an `NSNumber' instance
        else if([[tableColumn identifier] isEqualToString:@"visible"])
        {
            return [NSNumber numberWithBool:obj.visible];
        }
        else if([[tableColumn identifier] isEqualToString:@"opaque"])
        {
            return [NSNumber numberWithBool:obj.opaque];
        }
        else if([[tableColumn identifier] isEqualToString:@"animatable"])
        {
            return [NSNumber numberWithBool:obj.animatable];
        }
    
        return nil;
    }
    

    Using values from the table view to update the model

    - (void)tableView:(NSTableView *)tableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
    {
        // Retrieve the model object corresponding to `row'
        SomeObject *obj = [myArray objectAtIndex:row];
    
        // Set the object property corresponding to the column
        if([[tableColumn identifier] isEqualToString:@"name"])
        {
            obj.name = anObject;
        }
        // Since the new value (`anObject') is an object, we need to
        // convert it to `BOOL' by sending it `-boolValue'
        else if([[tableColumn identifier] isEqualToString:@"visible"])
        {
            obj.visible = [anObject boolValue];
        }        
        else if([[tableColumn identifier] isEqualToString:@"opaque"])
        {
            obj.opaque = [anObject boolValue];
        }        
        else if([[tableColumn identifier] isEqualToString:@"animatable"])
        {
            obj.animatable = [anObject boolValue];
        }
    }
    

    It is possible to make this code simpler by using Key-Value Coding but that’s left as an exercise after you master table view data sources. 😛

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

Sidebar

Related Questions

After adding a ribbon item, or calling a method that updates an item, the
After adding a boolean attribute to an object, fetching that object from the datastore
After adding RelayCommand class (that uses CommandManager class) into my Silverlight App I've got
We use Sajax for adding small Ajax code to sites. After running into a
After being told by at least 10 people on SO that version control was
After lots of attempts and search I have never found a satisfactory way to
After hours of debugging, it appears to me that in FireFox, the innerHTML of
After adding log4j to my application I get the following output every time I
After adding the /TSAWARE linker flag to one of my projects (Visual Studio 6),
After adding the key value pairs in NSMutableDictionary, when i retrive the key/values from

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.