Group UIButtons to limit "selected" state - objective-c

I have a row of 5 buttons, of which only one button should be "selected" at once. I call
[button setSelected:YES]
triggered by the corresponding IBAction to set the state of a touched button to "selected".
Is it possible to create some sort of button group where only the latest touched button of the row shows as selected and all others switch back to their "default" state? (kind of like radio buttons)

Is it possible to create some sort of button group where only the
latest touched button of the row shows as selected and all others
switch back to their "default" state? (kind of like radio buttons)
So radiobuttons then? A nice implementation called MNMRadioGroup does exactly that.
However, iOS also includes the native UISegmentedControl object which only allows one section to be selected at a time.

Related

Dynamically create views containing buttons - what about constraints?

I want a menu (hidden on the left side of my app) with a variable amount of buttons (depending on the user). I took the app over from another developer and he manually added every view and every button and it is a pain to maintain if you want to add another button in between or change something. So I want to redo it automatically.
But how can I achieve that? Let's say i have on the left x views, each containing an image, a button and a separator (to the button below). So I basically only create one single prototype view, button combo and reuse it for all other buttons. But how do I arrange them so the constraints are correctly set?
I would go with a table-view. Setup a cell with an image and a button, separators come for free in a table-view. Make sure the cell has a delegate for the button call-back or a closure to handle the button tap.
Add a controller/manager to control the number of views based on the user.

How to display show/Hide button in highlight regular mode of NSOutlineView?

How to display show/Hide button in highlight regular mode of NSOutlineView?
I have a grop item at the top of NSOutlineview. I try to display show/hide button in that group item, but I can't find any method to do it. The source list mode can display it but regular mode doesn't.
Is it possible to display show/hide button in highlight regular mode of NSOutlineview?
thanks for helping
This behavior is specific to the source list appearance. There is no public API for getting around this, as it's an intentional enforcement (on Apple's part) of standardized appearances. You could dig around in the headers to look for a way to "hotwire" things, but use of private API bars you from distributing your app through the App Store.
The easier (non-private-API-using) route is to create your own cell view with a borderless button with show/hide title. Use a mouse tracking area (see NSTrackingArea) on the cell view (the superview of your button) to set the button's alpha (via its animator) to fade the button in/out on mouse in/out. Your button would tell the outline view to expand/collapse its cell view's represented item (the easiest way would be to define an outlet to the button via your custom NSView cell view class and configure the button's target/action when the cell view is created for the item).

Adding A View To An Existing View Programatically

How can you add or replace a view within a view with code? I'm programming for OSX, not IOS.
I am using a drawer that utilizes a custom view. In the custom view I have two boxes, one with a custom set of icons that I want to stay static and another box that has the information related to that button. What I want to do is when a user clicks one of the buttons that the 2nd box view changes to reflect the info for that button.
For example, I have five buttons and the default 2nd box is "Info", if the user clicks the 2nd button in the first box view I want to change the 2nd box to be the "List" box instead while the 1st box with the buttons stays intact.
I'm not sure how this would impact constraints since while the first box is a fixed size, the 2nd box needs to be dynamic so that it fills in the "rest of the space" so that when the drawer size changes with the window size that the 2nd box is taking up the remaining real estate.
Thank you!
I have implemented such a scenario in the past using a tabless NSTabView, and an NSSegmentedControl (for the buttons). The NSTabView has it's -takeSelectedTabViewItemFromSender: action connected to the NSSegmentedControl, using Interface Builder.
In the Connections Inspector, this shows up like so:
This has the effect that the index of the selected NSTabViewItem in your NSTabView will correspond to the index of the selected segment in the NSSegmentedControl.

Is there a way to control the NSMenuItem item that is initially highlighted when opening a menu?

I'm working on the details of a symbols pop up button, similar to what Xcode 3 at the top of its editor window.
My controller object is the delegate of the NSMenu that is shown when the NSPopUpButton is shown. I implement the two methods numberOfItemsInMenu: and menu:updateItem:atIndex:shouldCancel: to populate the menu right before it's about to be displayed.
However, the title and image of the selected NSMenuItem have to change each time the user changes the selection in the editor NSTextView, or makes changes to the text; just as is the case with Xcode.
The problem I'm having is when the user goes to click on the NSPopUpButton to display the NSMenu, the selected NSMenuItem and the item that should be selected do not match up, since the menu doesn't have the proper number of items yet.
I'm wondering if there is a way to control which NSMenuItem is initially highlighted and tracked when the user clicks to open the menu. As it stands, the first item it always highlighted and tracked or, if the user had previously selected a item, that item is highlighted and tracked.
I tried explaining as best I could, but here is a image illustrating my problem:
I want the highlighted item to be the same as the selected item when the user opens the menu. Any ideas?
I would use a NSPopupbutton - it can do what you want. maybe you even hide it?
I am not very sure that I understood your problem but If we can add tags to these menu Items.
e.g.
[mMenuItemOne setTag : 1];
[mMenuItemTwo setTag : 2];
[mMenuItemThree setTag : 3];
[mMenuItemFour setTag : 4];}
we can select any Menu item using
[_popUp selectItemWithTag: _selectedItem];
Just a hint not a full solution.
Try to post an NSMouseMoved event to your app right after the menu shown.
Main problem is here to detect the position of the item you want to be highlighted.
Just a starting point.
Have you tried this NSMenuDelegate method:Handling Highlighting
– menu:willHighlightItem:
NSMenuDelegate Protocol Reference
Also you can store the NSMenuItem index in some var to keep track of the selected item for later use.
I'm not sure, do you want to move the mouse selection highlight (the blue stuff) or the checkmark?
In general, the checkmark is the thing you want to change. You can do so from your validateMenuItem: method (or at any other time if your item is set not to take part in validation) using the -setState: method.
The blue highlight is an indicator of the user's keyboard input or mouse location, and you should not mess with it. Changing it does not make any sense, as it would be changed back the moment the user moves the mouse even a single pixel.
That said, you can set the selectedItem of the NSPopUpButton, which will cause the entire menu to be moved so the selectedItem is under the mouse (assuming the mouse just clicked the popup button).
If your menu delegate method is called after the pop up button has decided what item to select, you can't use it. Instead, you could probably set the selectedItem and menu of the popup button from a NSPopUpButtonWillPopUpNotification handler.
If that is also called too late, you'll probably have to subclass NSPopupButtonCell and do it in an override of -attachPopUpWithFrame:inView: (I think that's the spot that should also work when you don't click and just hit the space key while the popup button is selected).

What is the correct UI guideline for an "Action" button in an iOS application on a UITableView per row?

My iPad (!!) app has a table view as the UISplitViewControllers details controller. To trigger various actions I use the following:
A swipe gesture on the cells to make a button visible that is called "Action".
Touching the action button shows a UIActionSheet with various options (Delete, Send, Download).
Touching one of the buttons in the action sheet triggers the action.
To achieve this behavior I customized the title of the "Delete" button which would normally be shown by the swipe gesture.
Please note that touching the cell itself will open/preview the touched item.
However, my test users complain that they cannot find the action menu because they would never try swiping the cells and if they would, they would do it to delete the entry. But they like that touching the cell previews the item.
Hence my question: what is the correct way of doing it? Show a disclosure button in every row (the little blue arrow to the right)? Show UIBarButtonItem in every row to bring up the action menu?
I'm so against it because it looks ridiculous to have a button in every row.
Sounds like a tricky situation; I'd either:
Add a detail disclosure button to each cell, and have that push a new view controller with the options (like the YouTube app).
Show the options in the "entry" view and have the "swipe" action an extra, discoverable feature (like the Twitter app).