Protocol not working


#1

I am using below code to disable deletebutton.

When setting the protocols, is there something else that I have to aware to code?

.h

[code]#import <Cocoa/Cocoa.h>
@interface Document : NSDocument {
NSMutableArray *todoItems;
IBOutlet NSTableView *itemTableView;
IBOutlet NSButton *deleteButton;
}

  • (IBAction)createNewItem:(id)sender;
  • (IBAction)removeSelectedItem:(id)sender;
    @end
    [/code]

.m file somewhere

- (void)tableViewSelectionDidChange:(NSNotification *)notification{ if ([itemTableView selectedRow] > -1) { [deleteButton setEnabled:YES]; } else { [deleteButton setEnabled:NO]; } }


#2

Is the tableViewSelectionDidChange: method being called at all?

You can answer this with a simple log:

- (void)tableViewSelectionDidChange:(NSNotification *)notification{
    NSLog (@"--->%s", __PRETTY_FUNCTION__);

    if ([itemTableView selectedRow] > -1) {
        [deleteButton setEnabled:YES];
    } else {
        [deleteButton setEnabled:NO];
    }
}

If not, then make sure that the TV (itemTableView)is connected to its delegate.

If it is being called, then make sure that itemTableView is not nil; ditto for deleteButton.


#3

Connected delegate and it is working.

What chapter of the book did we get introduced for delegate connection in xib file though?

Thanks,