title: How to create an action from selecting a row from an NSTableView
body: <p>When I select a row from <code>NSTableView</code>, it is not running the code from <code>tableViewSelectionDidChange</code> method. I had put break points in this method and it is not even going into the method.</p>
  
  <p>Any ideas? Am I missing something in my initialiser?</p>
  
  <p><strong>PersonController.h</strong></p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  @interface Person : NSObject {
    IBOutlet NSTableView *personsTable;
    NSMutableArray *personsList;
    NSMutableArray *personCollection;
  
    IBOutlet NSTextField *selectedPersonName;
    IBOutlet NSTextField *selectedPersonGender;
  @private
  
  }
  
  - (void)tableViewSelectionDidChange:(NSNotification *)aNotification;
  
  @end
  </code></pre>
  
  <p><strong>PersonController.m</strong></p>
  
  <pre><code>#import "PersonController.h"
  #import "Person.h"
  
  
  @implementation PersonController
  
  - (id)init
  {
      self = [super init];
      if (self) {
          personsList = [[NSMutableArray alloc] init];
          Person *person = [[Person alloc] init];
  
          // Create person 1
          person.name = @"Bob";
          person.gender = @"male";
  
          // Append to array
          [personsList addObject:person];
          [person release];
  
          // Create person 2
          person = [[Person alloc] init];
          person.name = @"Fred";
          person.gender = @"Unknown";
  
          // Append to array
          [personsList addObject:person];
          [person release];
  
          [personsTable reloadData];
      }
  
      return self;
  }
  
  - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
      return [personsList count];
  }
  
  - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
      Person *person = [personsList objectAtIndex:row];
      NSString *identifier = [tableColumn identifier];
  
      return [person valueForKey:identifier];
  }
  
  - (void)tableViewSelectionDidChange:(NSNotification *)aNotification
  {
      NSInteger selectedRow = [personsTable selectedRow];
      if (selectedRow == -1)
      {
          // these should be localized, but use string constants here for clarity
          [selectedPersonName setStringValue:@"No selection"];
          [selectedPersonGender setStringValue:@"No selection"];
      }
      else
      {
          Person *selectedPerson = [personCollection objectAtIndex:selectedRow];
  
          [selectedPersonName setStringValue:[selectedPerson name]];
          [selectedPersonGender setStringValue:[selectedPerson gender]];
      }
  }
  
  - (void)dealloc
  {
      [super dealloc];
  }
  
  @end
  </code></pre>