Sahitya Tarumani
Sahitya Tarumani

Reputation: 429

Managing subviews from superview?


I have a window with a content view. I load a subview on to it from a different nib file programmatically. is there any way that a change on the subview can be captured by the controls on the window's content view?

For instance, I have a tableview on the subview. If the selection of this tableView changes, i want to enable a button on the windows's content view. Is it possible? If yes, please guide..

Thanks in advance..

Upvotes: 3

Views: 796

Answers (1)

danielv
danielv

Reputation: 3097

There are few ways

You can set the object that creates the subview as a delegate for the tableview and implement tableViewSelectionDidChangein that object.

Or you can subscribe to NSTableViewSelectionDidChangeNotification notification, passing your tableView:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tableViewSelectionDidChange:) name:NSTableViewSelectionDidChangeNotification object:tableView];

and handle it in :

- (void)tableViewSelectionDidChange:(NSNotification *)aNotification {
    NSTableView *tableView = (NSTableView *)aNotification.object;
    NSLog(@"selection changed: %i", [tableView selectedRow]);
}

Upvotes: 6

Related Questions