I have in my code some functionality to open a popover anytime an event happens. Problem is that if those events happen one after the other the popovers opened are overlapped.
I would like to close one popover when opening new one.
Is there any way to get from nswindow if there is an active popover?
Thanks in advance and regards
I think you need play with NSPopover's notification methods such as:
- (void)popoverDidShow:(NSNotification *)notification;
- (void)popoverWillClose:(NSNotification *)notification;
And add some logic which will hide not closed popover...
Finally I was able to figure it out by using notifications posted:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(popoverWillShow:)
name:NSPopoverWillShowNotification
object:nil];
And then in the selector I compare the objects: (popover is an NSPopover)
- (void)popoverWillShow:(NSNotification *)notification {
if (![popover isEqual:[notification object]])
[self close];
}
Related
I have a NSView displayed over a NSOpenGLView. I am using the 'setWantsLayer:YES' to force the NSView to appear over the opengl context. But when I minimize the window and deminimize it again, the NSView is no more over the NSOpenGLView.
Is there a way to prevent this behaviour?
Ok, I have found a solution for this issue. Is not maybe the best, but solves the issue.
First, I have declared a notifier in my appDelegate class:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(windowDidDeminiaturize:)
name:NSWindowDidDeminiaturizeNotification object:nil];
This notifier detects the window deminimization event. Then, in the callback function, I do this:
- (void)windowDidDeminiaturize:(NSNotification *)notification
{
[view_PlaybackView setWantsLayer:NO];
[view_PlaybackView setWantsLayer:YES];
}
And the view is again shown in front of the NSOpenGLView.
I have tried to deal with this issue for too long. Please give me any of your thoughts.
I am presenting a View Controller from an SKScene by sending a Local Notification. [[NSNotificationCenter defaultCenter] postNotificationName:#"closeScene" object:nil];
The notification is handled in the beginning view controller.
- (void)viewDidLoad{ [[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(closeScene) name:#"closeScene" object:Nil];
[super viewDidLoad];}
Then:
-(void)closeScene {
//Remove the SKView, or present another viewController here.
constructionViewController *view = [[constructionViewController alloc] init];
[self presentViewController:view animated:YES completion:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"closeScene" object:nil];
}
And every time the notification is sent, I get the warning:
Warning: Attempt to present <constructinoViewController: 0x10ae64160> on <constructinoViewController: 0x10ab329d0> whose view is not in the window hierarchy!
Any help would more than appreciated. Thank you in advance!
When is closeScene called, exactly - before or after viewDidAppear gets called?
The error you're seeing usually happens when you try to present a view controller before the parent is actually displayed on screen. Typically this is because you've called presentViewController before the parent's viewDidAppear method has been called.
Try adding a logging statement to viewDidAppear and see whether it appears in the logs before or after your 'view is not in the window hierarchy' error. If it appears after you'll know what the problem is, and how to fix it (make sure presentViewController is only called after the parent view controller has been displayed). If it's before you probably have an altogether different problem...
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?
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];
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.
I have App, playing Videos from web
everything works fine
but when user leave the app for reading email or anything
and come back the player gone!! big problem
so, I want user resume watching after come back to app
here is my code so far
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didEnterforground) name:UIApplicationWillEnterForegroundNotification object:nil];
the Methods
- (void) didEnterBackground
{
[theMovie.moviePlayer pause];
NSLog(#"Playing pause");
}
- (void) didEnterforground
{
[theMovie.moviePlayer play];
NSLog(#"Playing resume");
}
for know I use [self presentMoviePlayerViewControllerAnimated:theMovie]; NOT playing in view
should that's code works but, nothing works
Please Help
Thanks in advance
The answer is very simple, edit info.plist.
Add background competence, required background modes, set category App plays audio
Try it!
I have a MAAttachedWindow that shows itself when a status bar item is clicked. I need to have it close when its clicked outside of. I found some other directions that say to set it as a delegate and use - (void)windowDidResignKey:(NSNotification *)notification to detect when the user exits the window. I've tried it many times but can't seem to get it working which is probably because I didn't correctly set the delegate. Whats the best way to set the delegate so it will respond to the notification? The code is available here.
Thanks in advance
I found out to get the notification you have to register for it.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(windowDidResignKey:)
name:NSWindowDidResignKeyNotification
object:self];