One can set a NSStatusItem's behaviour property to removalAllowed (NSStatusItemBehaviorRemovalAllowed)
Then a user can remove the item from the status bar using drag and drop.
Example: removing the WiFi status item from the status bar
However, I am unable to detect when the statusbar is being removed so I can remember it and not show it the next time the user starts the app. There is no delegate or notification and the statusBar property is readonly so I can't override the setter.
Any idea? :)
The documentation for NSStatusItemBehaviorRemovalAllowed says:
Upon removal, the item’s visible property changes to NO. This change is observable using key-value observation.
So you could add a KVO observer for that property, and if it changes to NO (and assuming you didn't set it to NO), don't show your status bar item on future launches.
That said, in testing this out: the system handles this for you fairly well. When you create your status bar item, don't set the visible property, and set an autosaveName. If the user removes your item from the status bar, the system writes that to the app's preferences in ~/Library/Preferences, and your status bar item won't be visible on future launches.
To restore the visibility, manually set the visible property to YES.
Related
I am building this app that will sit on the menu bar.
So, as normally is done with this kind of app, you adjust the statusItem menu to be the menu of your app.
The items on that menu trigger actions on the first responder, that in my case is the viewController of that app.
This is the problem: this works if the app is active but if the app is not active or hidden, this fails. I guess the actions triggered by the menu items will fire to the responder chain but there is no one listening, because the app is hidden or not active.
How do I do in that case? Should I create a singleton and add that singleton to the responder chain? I say singleton because that would be always loaded in memory. Does this singleton have to be a subclass of some special class?
How to do if actions from this menu should trigger stuff in the viewController?
You should be able to handle first responder in the AppDelegate, which should work if the app is not active.
See NSEvent.addGlobalMonitorForEvents(matching:handler:) & note the discussion:
Key-related events may only be monitored if accessibility is enabled or if your application is trusted for accessibility access (see AXIsProcessTrusted()).
I am new to iOS development. I am having a weird situation, not every time but very often. My textfield is getting cleared automatically when I come back to the same screen using back button. Code as:
self.navigationController?.popViewControllerAnimated(true)
Problem happens in both simulator and device.
It happens because the content view is refreshed everytime when you navigate app to previous viewController this make refresh to all ui components as well. What you need to do here just save the textfields value temporally to any persistent storage like local db or using userDefaults then assign the value again using viewWillAppear() method because this method executes everytime when you navigate back your app to vc.
viewWillAppear(): Called just before the view controller’s content view is added to the app’s view hierarchy. Use this method to trigger any operations that need to occur before the content view is presented onscreen. Despite the name, just because the system calls this method, it does not guarantee that the content view will become visible. The view may be obscured by other views or hidden. This method simply indicates that the content view is about to be added to the app’s view hierarchy.
Is it possible to remove status bar for a particular Interface Controller or customise Interface controller title text in any way ?
As of Apple Watch Programming Guide you can customize interface controller title text color by setting your App’s Key Color.
Every WatchKit app has an associated key color, which is applied to the >following UI elements:
-The title string in the status bar
-The app name in short look notifications
An app’s key color is stored in the Global Tint property of the app’s storyboard. To access this property, select your storyboard and display the File inspector. Select one of several preexisting colors from the popup menu or use the color picker to specify a custom color.
This is all we have as of today.
About if it is possible to hide the status bar...
The closer result you will get is by using modal interfaces.
In this ones, the clock will be invisible but the status bar will remain there holding the interface title.
I've got a TabBarController, that in it's first instance contains a ViewController for login purposes.
After a successful login another viewcontroller is pushed on.
I've noticed that if you select the tab again your returned to the top of the stack, What I would like to happen is your returned to the location you left.
Is this something that needs to be managed myself or is there a property or something to that effect that could be set.
You have to manage that yourself by keeping state. You'd probably want to implement shouldSelectViewController in a UITabBarDelegate to get notified when the user clicks in the tab bar.
This is sent before anything is switched around.
I have a UISearchDisplayController that displays some cells after a user has searched. After the user clicks on the cell, I am pushing a new view to my nav stack. How can I remove searchResultsTableView from the view so that when the user goes back, he doesn't see the searchResultsTableView?
See the documentation of UISearchDisplayController it sais:
setActive:animated:
Displays or hides the search interface, optionally with animation.
- (void)setActive:(BOOL)visible animated:(BOOL)animated
Parameters
visible
YES to display the search interface if it is not already displayed; NO to hide the search interface if it is currently displayed.
animated;
YES to use animation for a change in visible state, otherwise NO.
Discussion
When the user focus in the search field of a managed search bar, the search display controller automatically displays the search interface. You can use this method to force the search interface to appear.
Availability
Available in iPhone OS 3.0 and later.
Declared In
UISearchDisplayController.h