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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:44:47+00:00 2026-05-13T19:44:47+00:00

I’m learning Cocoa, and I’ve got a problem: I would like to bind the

  • 0

I’m learning Cocoa, and I’ve got a problem: I would like to bind the content of an NSMutableArray to an NSTableView, with bindings. I read many documentations about them, but I can’t manage to make them work (nothing is displayed in my table).

Here are the facts:

I created a simple model, called MTMTask which contains 2 properties, priority and text:

MTMTask.h

@interface MTMTask : NSObject {
 NSString *priority;
 NSString *text;
}

@property(copy) NSString* priority;
@property(copy) NSString* text;

- (id) initWithPriority :(NSString*)newPriority andText:(NSString*)newText;

@end

MTMTask.m

#import "MTMTask.h"

@implementation MTMTask

@synthesize text, priority;

- (id) initWithPriority:(NSString *)newPriority andText:(NSString *)newText {
 if (self = [super init]) {
  priority = newPriority;
  text = newText;
  return self;
 }
 return nil;
}

@end

Then I’ve created the MTMTaskController :

MTMTaskController.h

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

@interface MTMTaskController : NSObject {
 NSMutableArray *_tasksList;
}

- (NSMutableArray *) tasksList; 

@end

MTMTaskController.m

#import "MTMTaskController.h"

@implementation MTMTaskController

- (void) awakeFromNib
{ 
 MTMTask *task1 = [[MTMTask alloc] initWithPriority:@"high" andText:@"Feed the hungry cat"];
 MTMTask *task2 = [[MTMTask alloc] initWithPriority:@"low" andText:@"Visit my family"];

 _tasksList = [[NSMutableArray alloc] initWithObjects:task1, task2, nil];
}

- (NSMutableArray*) tasksList
{
 return _tasksList;
}

@end

And finally I edited the MainMenu.xib: I added a NSObject and set its class to MTMTaskController. Then I added an NSArrayController, called TasksListController, with its content outlet bound to MTMTaskController.tasksList. I also set its mode to Class and class name MTMTask. I bound the value outlet of two columns of an NSTableView to TasksListController text and priority.

But when I run the program, well, it’s not really a success: nothing shows up in the table.

Have you got an idea concerning my problem? I think I’m missing something but I can’t figure what.

Thanks in advance!

  • 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-13T19:44:48+00:00Added an answer on May 13, 2026 at 7:44 pm

    When you are allocating objects for the controller in awake from nib, you create the objects, add them to an array and then set that array as the task list.

    The thing about bindings is that you need to be aware of KVO (Key value observing) which is the mechanism by which bound objects know that the things they have bound to have changed.

    In the awake from nib method you have just set the array directly which doesn’t invoke KVO.

    I have created an example Xcode project (Xcode 3.1) which you can download from here. This creates a property for the task list and within the awakeFromNib method I am assigning the array using property syntax, which takes care of KVO for you:

    - (void)awakeFromNib {
        Task *task1 = [[Task alloc] initWithPriority:@"high" andText:@"Feed the cat"];
        Task *task2 = [[Task alloc] initWithPriority:@"low" andText:@"Visit my familiy"];
    
        self.taskArray = [[NSMutableArray alloc] initWithObjects:task1, task2, nil];
    

    }

    Alternatively, you could sandwich the assignment in willChangeValueForKey: and didChangeValueForKey: messages, but I’ll leave that as an excercise for you.

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

Sidebar

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.