Panel & Delegate methods of its controls

Discussion in 'Mac Programming' started by satyam90, Mar 25, 2008.

  1. macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #1
    Hi, I am having a NSTableView inside a panel. I implemented "- (void)tableViewSelectionDidChange:(NSNotification *)aNotification".
    But I noticed that it is not called at all even though I am changing the table view's items. Can anyone tell me why this is happening? How to make the delegate called inside a Panel?
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    So your table view is inside an NSPanel, and the tableViewSelectionDidChange: notification is not being called? Are you sure your delegate is properly setup? You could also try subscribing to the NSTableViewSelectionDidChangeNotification notification manually (especially if you're using bindings).
     
  3. thread starter macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #3
    Hi Kainjow,
    I didn't set the delegate. I implemented "- (void)tableViewSelectionDidChangeNSNotification *)aNotification" in the controller of the panel.
    Can you please some reference how to handle this.
    Also can u tell me how to subscribe to notification manually.
    Thanks & Regards,
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    tableViewSelectionDidChange: gets called only in 2 situations:

    1) you set the NSTableView delegate
    2) you added your class as an observer of the NSTableViewSelectionDidChangeNotification notification

    So if you didn't do 1, you need to do 2:

    Code:
    - (void)awakeFromNib {
        [[NSNotificationCenter defaultCenter] addObserver:self
            selector:(tableViewSelectionDidChange:)
            name:NSTableViewSelectionDidChangeNotification
            object:myTableView];
    }
    
    - (void)tableViewSelectionDidChange:(NSNotification *)notification {
        // yay it changed
    }
    You will need an IBOutlet to your NSTableView.
     
  5. thread starter macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #5
    Hi Kainjow,
    The second option is working fine but not the first one.
    For first option, in IB, I selected table view control and then associated its delegate to my controller class where I implemented textDidChange. Do I have to include or change anything for that?
     

Share This Page