One menu item to toggle between two states in WatchKit Context Menu - watchkit

I'm setting up a Menu and Menu Items in Storyboard, and want one menu item to toggle between two states e.g. on/off, Celcius/Fahrenheit, etc.
However, control-dragging from a menu item to the interface controller doesn't let me create an outlet, but only has option to create an action. So although I can set up an action to toggle between two states, I'm not being able to change its title and image to show the current button state.
Is there a way to implement this correctly in WatchKit?

Yes, you can do it this way - whenever you want to toggle your state - clear menu items:
[self clearAllMenuItems];
and then set up new menu items:
[self addMenuItemWithImageNamed:#"myImage" title:#"action title" action:#selector(actionMethod)];

Related

NSTableView (or NSOutlineView) column hiding through contextual menu : a "no code" solution

I searched SO for the best solution to this question, found several clues, while not fully satisfying IMO. So I post below my no-code solution.
The goal is to have, as in Finder or other native applications, a contextual menu on the header bar of a table or outline, allowing to select which columns are visibles.
In IB storyboard, add all the columns you need into the table view.
You may set some of them hidden by default.
Ctrl-drag each column from the IB document outline view to the scene controller code view, in order to automatically create weak IBOutlets for each column. The purpose is to be able to target a given column in bindings.
__weak IBOutlet NSTableColumn *my_column;
Add a menu to the storyboard scene with the same number of item as the columns you plan to hide. You do not have to give title to menu items (see next point).
For each menu item, in the bindings pane, add two bindings :
Bind the item title to the column title property through your controller outlet : controller_name.my_column.title. This way the menu item will stay in sync with column title, should the code need to change it.
THIS ONE IS KEY : Bind the value of the menu item to the column hidden property : controller_name.my_column.hidden. Add a NSNegateBoolean transformer for the menu tick to be meaningful.
Attach the menu to header menu : ctrl-click on the table header view and make connection from the menu outlet to the menu created in #3.
That it's. No code beside the IBOutlets added in #2.
The bindings being two ways, un-ticking a menu item will hide the bound column. Also, if the code hides a column the bound menu item will reflect its state.

UINavigationController and UINavigationItem

Apple's documentation on UINavigationItem states the following:
The managing UINavigationController object uses the navigation items
of the topmost two view controllers to populate the navigation bar
with content.
Why the topmost two view controllers instead of just the topmost? Is it just so that when you pop the view controller, it fades one item out and another in?
I think it's because the title of the "Back" button is (by default) the navigation title of the view controller just underneath the top one.
Navigation title: Title of top view controller.
Back Button title: Title of previous view controller.

Drupal 7 : How to control Visibility of Main Menu based on selection of Menu Item in User_Menu?

I have Main_Menu which is my Primary and User_Menu which is my Secondary Links Menu. I want to show the Main_Menu when user clicks on one of the Menu Items in the User_Menu. How do i achieve this?
I'm not sure I understand the use case for showing the primary menu after clicking on the secondary menu. That seems to contradict the meanings of "primary" and "secondary". :)
But you might get some use out of the Menu Block module: http://drupal.org/project/menu_block

How to identify the viewcontroller is clicked from More Tab or Separate tab in UITabBarController?

I have the navigationcontroller based viewcontroller and I overriding the root view controller navigation bar back button in to my custom segment control with different purpose. This navigation controller is placed one of the separate tab in the uitabbarcontroller. If this is used as the separate tab bar then no problem.
But if i use this navigationcontroller inside the more option in tabbarcontroller i am not able to come back to the more option list because of backbutton is overridden in my navigationcontroller.
My idea is add one back button only if my navigationcontroller is used more option tab otherwise i need to hidden the back button.
Please help me in this issue?
You can check if a view controller is in the 'more' section as follows:
BOOL isOnMoreNavigationController = [tabBarController.moreNavigationController.viewControllers containsObject:myViewController.navigationController];
From a UI consistency perspective it might be better to always show the back button in its standard position and move your custom buttons to some other place.

UINavigationController custom titleView

I have a navigation controller with a root view controller for which i have the customised titleView instead of normal title for the navigation item.
If i pushed a new controller in it , the default back button title is "back", Since i have used custome titleView.
I want it to be different. I tried by setting the title in backbaritem of the root view controller, but no use.
I can create a bar button item in my pushed controller and i can set it as leftbar item, But i want it like a normal back button. [Pointing towards backward]
Is it possible to set title for the back button , if i have a custom titleView ?
Is it possible to create a bar button item as like as default back button.[Pointing towards back , other than plain,border...etc] ?
Regards,
Balaji R.
I got it.
Even though i have custom titleView for my navigation item, I can still set the title for the same navigation item where it wont be taken for the title display in navigation item . but it will taken as the title of the back button when some other controllers are pushed into it.
So , Now i'm having both title [Used for back title display] and titleView [custom view] in the navigation item.
Thanks,
Balaji R.

Resources