Question

I have a delegate method of an NSSplitView like this:

- (void)splitViewWillResizeSubviews:(NSNotification *)aNotification
{
    NSLog(@"RESIZE!");
}

This method is called whenever I drag a divider, so it registered properly. I would like to call this from another object, and was thinking to use this:

[[NSNotificationCenter defaultCenter] postNotificationName:NSSplitViewWillResizeSubviewsNotification object:self];

According to the Apple docs, this is the notification that should be sent to call the delegate method. However, it does not work. Does anyone have an idea what I am doing wrong?

Was it helpful?

Solution

You can just invoke the method manually

NSSplitView * yourSplitView; //Get reference to your splitview
id yourSplitViewDelegate = [yourSplitView delegate];
[yourSplitViewDelegate splitViewWillResizeSubviews:nil];//Optionally create the NSNotification with relevant data

If you really want to go through notification center, make sure self in your question is the NSSplitView.

NSSplitView * yourSplitView; //Get reference to your splitview
[[NSNotificationCenter defaultCenter] postNotificationName:NSSplitViewWillResizeSubviewsNotification object:yourSplitView];

OTHER TIPS

Turns out that I needed to manually register the delegate class for the NSSplitViewWillResizeSubviewsNotification notifications!

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(splitViewWillResizeSubviews:)
                                                 name:NSSplitViewWillResizeSubviewsNotification
                                               object:vc];

where vc is the viewcontroller that should be sending the notifications.

This is unexpected behavior (to me), since an <NSSplitViewDelegate> is expected to register automatically for NSSplitView... notifications.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top