NSStatusItem not shown after sleep - cocoa

I've got a small Cocoa problem. I have a StatusBar application that has an NSStatusItem in the Menu Bar. It is drawn by a custom View as shown here. When the Main view of the app is hidden (most of the time), the computer goes to sleep and awakens again, I lose the icon and a blue rectangle is shown. Has anyone of you got any idea what I can do about it. It doesn't happen when the Main View is shown.

The problem was fixed by replacing [theItem drawStatusBarBackgroundInRect:[toolbarView frame]] to [toolbarView setNeedsDisplay:YES];
Thanks AlBlue for getting me in the right direction.

Related

How do I place text fields correctly within an animated UIView?

I am having problems with animating an UIView.
Everything is actually pretty basic:
My storyboard, because it easier to show a pic than to explain everything.
As you can see, there is a white UIView in the middle ( behind the gray label that says "Navi ein" ). It has to TextFields and one button in the right bottom corner.
I now added an animation to this UIView, so when the user clicks the button "Navi" (placed in the navi.-bar, top left), the UIView flys in from the top to the center (centerY-constraint and alpha animation, very simple).
The animation works for the UIView, but the TextFields and the button are not shown after it. My question is: why? I would really appreciate your help! :-)
Please let me know if you need some code extracts, but it shoudn't be necessary.
EDIT: I now found the text fields and the button in my View Debugger, I just forgot to uncheck "Only show displayed views". But how to figure out what makes them disappear (or not even appear) when the app launches?
View Debugger
I am so sorry! I just saw that I set all three items to hidden in my code.
I've never thought about that so far, I just looked in my storyboard.
So the problem is solved, I just deleted the lines "streetTextField.isHidden = true" and so on.
Nevertheless, I think it is good to hear and to see that some problems that seem to be hard are very easy to solve.

How do I prevent the menu bar from moving down when my popover is open?

I have an app with a popover that appears on a status bar item. The thing is, when you click on the icon while you're in a full screen app, then move the mouse away from the menu bar to click on something in the popup, the menu bar moves up, and so does the popup. It's annoying.
Anyone know of any way to solve this? I've tried attaching an invisible menu to the popup, but I can't get the menu to be invisible.
Screenshot for clarity, the annoying part is where I wave my mouse around:
The popover window is moving because its parent window is the status item window, and when the parent window moves, the child moves with it. (Before I investigated this, I didn't even know Cocoa had parent and child windows.) I solved the problem with this code immediately after showing the popover:
NSWindow *popoverWindow = self.popup.contentViewController.view.window;
[popoverWindow.parentWindow removeChildWindow:popoverWindow];
Now, the menu bar still moves up, but at least the popup stays in the same place.
Either use Carbon events or watch for things happening to the menu bar (window of type NSStatusBarWindow):
Notifications of type
NSWindowDidChangeOcclusionStateNotification
NSWindowDidMoveNotification
NSWindowWillCloseNotification
NSWindowDidCloseNotification
with an object of class NSStatusBarWindow should give you enough information about the menu bar showing or hiding to add proper handling.
Super-hacky approach:
Custom window with some super-high window level to make it appear over the menu bar, then add a transparent custom view to the new window that catches and handles/blocks mouse clicks according to your needs.
Or:
Get the window instance the popover is using to display and track/handle NSWindowWillMoveNotification / NSWindowDidMoveNotification.
I converted #tbodt's answer to Swift 4 and confirmed that is resolves this issue:
let popoverWindow = popup.contentViewController.view.window as? NSWindow
popoverWindow?.parent?.removeChildWindow(popoverWindow!)

xcode two uitabbarcontrollers one page. auto-rotate issue

Summery:
I have a custom UITabBarAutoRotateController which returns YES from shouldAutorotateToInterfaceOrientation. This has no effect.
If I minimize and show the app again, the rotation issue goes away.
How do I refresh the screen so the user does not have to do this (so rotation works again)?
Details (setup graphically, so no code):
I have two UITabBarController in MainWindow.xib. I only want one to show at a time. So I am linking graphically rootViewController = tabBarController_name1. There is also tabBarController_name2.
I will also have an alert MessageBox for a user to choose what type of application they need, and it will choose a tab bar controller based on their request (per customer definition). This is commented out for now.
There is a bug with Rotation when two UITabBarControllers exist on the same xib. When I try to rotate the screen, it stays upward with wherever the main screen button (power button looking button) faces. HandleOrientationChange does not get called on the active custom ViewController being shown.
The reason I believe it's a bug is because if I hit the main screen button (minimizing the application), and click back on the application (brings it back to the foreground), rotation works perfectly!
Sorry for making you read all that mumbo :). My true question is, "Is there anyway I could refresh the main window or likewise UITabBarController's to get rotation working (without requiring the program be minimized and shown)"? A work-around, if you will?
p.s. I cannot use Storyboard for backwards compatibility reasons. The customer will be receiving this code/project. So I would like to keep this in one graphical page, rather than hiding/showing UITabBarItem's.
EDIT: two-uitabbarcontrollers-and-autorotation and uitabbarcontrollers-and-uinavigationcontrollers were both helpful, but did not address "why" this issue happens. "noob" here when it comes to xcode :)
Tab bar controller inside a navigation controller, or sharing a navigation root view is the answer. Do not use a TabBarViewController. Which, as a noob, I'm not quite sure why TabBarViewController exists (or at least isn't depreciated).
Dragging two TabBarViewControllers into the same page should result in a warning saying that you probably want to implement TabBarViewController by making a custom UIViewController and attaching a plain UITabBar to it.
Frustrating...but finally making progress :)

NSOutlineView - scroll to top at launch

Got an NSOutlineView that is configured in the controller's awakeFromNib, with a datasource and autosaved expanded nodes.
All working like a charm.
The problem is that somewhere, somebody is saving the state of the scroll position, too.
This means that at launch of the app, the outline view can appear scrolled to the bottom - if that was how the user left it last (this is on Lion if it matters).
What is the best way to open the app with the outline view scrolled to the top? Preferably in awakeFromNib, or at least so the user won't be seeing a scroll movement.
I recently started having problems with my NSOutlineView being scrolled down (so that I couldn't see my elements until I scrolled up), and I used this method :
In my applicationDidLaunch: method I use this :
[outlineView scrollPoint:NSMakePoint(0.0f, [outlineView frame].size.height)];
And it seems to work. (I also had the same problem on an IKImageBrowserView, and the same piece of code worked on that too)
Hope this solution suites you better ^^
What about [outlineView scrollToVisible:0]; ?

UIPopovercontroller detached from UIButton

I'm running into a problem with a detached UIPopovercontroller and am hoping someone has seen this behavior before.
My app runs in Landscape mode and offers a number of popover elements using the presentPopoverFromRect call. Some are launched from within the top view while others are presented from a view buried deep in the display. The popovers seem to work fine if the popover is presented from the upper 2/3rds of the iPad's display however when attempting to launch a popover from the bottom 1/3 of the display the popover is displayed detached from the UIButton. The x coordinate appears to be correct, however the y coordinate of the popover tends to be in the middle or top of the iPad screen.
I've played around with presenting the popover using a fixed position by creating a CGRect object in the lower 1/3 of the display but when the iPad renders the popover it either renders the popover in the upper 2/3rd of the view or the very bottom of the screen (if I force the CGRect value to a large y value).
At this point I'm out of ideas and hoping someone on the forum has seen this or can make suggestions as to what to try.
Thanks for any and all help,
Wes
I was able to fix my issue and thought that I'd share my solution incase someone else has the same problem.
The solution was to add a call to set the popover size BEFORE calling presentPopoverFromRect.
[mySettingsPopoverController setPopoverContentSize:CGSizeMake(320, 320) animated:YES];
[mySettingsPopoverController presentPopoverFromRect:sender.frame inView:self.navigationButtonsView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Before, I wasn't setting the popover content size prior to presenting the popover. In the viewDidAppear method of the viewcontroller of the popover I was resizing the popover to size to the tableview in the popover. Apparently by not setting the popovercontentsize before presenting the popover you get undefined behavior including the possibility of having the popover detach from the element that it is suppose to be attached to.
Wes

Resources