UI picker Trying to do it the right way - objective-c

I am trying to use a UI picker like a combo box in C#. User clicks on a TextField, I have set the inputView to be the picker. This works fine. User clicks on the row and I get the item on that row and place it in the textfield.
However, when the application loads, this picker is visible! I don't want it to be visible. I want to be able to make it visible when the user clicks on the textbox and then when he or she moved off I want to hide it. How do you do this?
Also , is it possible to have the picker only if the user wants to do a lookup like CTRL click. Otherwise, it uses the keyboard? How do you toggle back and forth between the keyboard and the picker.
For example suppose user wants to add a new book. He/she clicks on the authors textfield and he/she either types the author ( a new author that does not exist in the database) or select and existing author from the list.
Thanks

The best way to do this is using the inputView property of the textField. You can just set that to the picker and it should handle the rest for you.

Related

OSX: Move keyboard focus between textfields and buttons using tab key

I am trying to toggle between textfields and buttons on my view using keyboard's tab button. The switching between textfields work but it does not switch between buttons. The view is shown as below.I did not find enough resources online to proceed further. Does anyone know how to resolve this?
There is nothing you can do with that issue.
It turns out that in the System Preferences > Keyboard > Shortcuts there is a checkbox, where you can change behaviour of the whole system:
To move keyboard focus only between text boxes and lists
To move keyboard between any of controls
And by default first checkbox is pressed.
As an addition. By default, NSWindow assigns an initial first responder and constructs a key view loop with the objects it finds. You can also change key view loop by calling this method: setNextKeyView.
For example,
[firstTextBox setNextKeyView:secondTextBox];
[secondTextBox setNextKeyView:secondButton];
[secondButton setNextKeyView:firstButton];
[firstButton setNextKeyView:firstTextBox];
This means that for users who expect moving control focus through all controls, this will work. And for those who have disabled this feature in settings, this won't work.
You can right-click on text field, drag "nextKeyView" and drop on another text field that you want to focus next when user press tab. Look like my picture below:
To add to #mjonka's answer, To move focus between controls is dependent on user's keyboard-shortcuts settings. What could be alternate solution is to just selecting your desired action button in your xib file and setting "Key Equivalent" value field to "enter" key in Attributes inspector as shown below. Same thing can be done for cancel button by setting "Key Equivalent" value to "Esc" key.

UIText field does not respond to touch after switching view

In my app, I have a text field that works fine, however after going back to the main menu and then back onto the page with the text field, the text field becomes un-touchable, the keyboard does not show no matter how many times you click it.
Here is a screen shot of the interface http://tinypic.com/view.php?pic=y11sm&s=6
I think I may have to add code or connect an action with the text field, but how?
Thanks for your time.
You can remove subviews that you don't use anymore like #Kim has already told you or if you need these subviews but they are blocking the action, you can bring your textfield to front using,
[your_view bringSubviewToFront: your_textfield];

vb.net winforms datagridview how to tell where the user clicked in a cell

I am adding a custom column to a custom datagridview. One of the options this new datagridcolumn has is the ability show a value and then a button to allow the user to click on the button and something will happen. The button only takes up the right portion of the cell and the rest is a value. This button and value are displayable always and the button should always be able to be clicked on. In datagridview's display mode the value and button are painted. What I need help on is how to tell whether the user clicked on the button portion of the cell. Can someone please provide example code on how to do this?
Thanks,
Greg
Never mind I figured it out. I just put some logic in the cellclick event of the datagridview to get the GetCellDisplayRectangle and converted that to screen points and got where the mouse is on the screen and did a bounds test with the rectangle contains method.

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).

How can I keep an NSPopUpButton open after the user selects a menu item?

I have an NSPopUpButton providing the NSMenu for a status item with a custom view. The popup button displays a list of links. When the user selects a link from the list, the link is displayed in the user's browser (in the background).
Naturally, the menu closes every time the user selects a link.
I would like to change this: I want the menu to stay open while the user clicks on various links, all of which can be opened in the background. The menu can then go away when the user clicks elsewhere.
How can this be accomplished? Should I subclass NSMenuItem and intercept the mouse clicks somehow? Overlay a transparent NSView on the popped-up menu and, again, intercept the clicks somehow? I make these suggestions blithely, but I would have trouble implementing either of these...pointers to the right methods for override would be appreciated.
Instead of using a menu, one might use a collapsible box.I have seen that in many apps ( also provided by Apple) , so I guess this is the recommended style guide for multiple selections.
The collapsible box expands when you click the disclosure button, and it gives free all items desired - like a tableview with checkboxes.
Views below this box must move down in this case, not to interfere with the box.
Clicking again on the disclosure button will shrink the box back to its origin. The effect is similar to closing a menu.
Usually you should not bend a control too far past it's original intent. Users expect pop up buttons to close after making a selection. I don't think you should, or can, force NSPopUpButtonCell to behave in this way. If you do, you'll be subclassing and modifying the control so heavily that it might change/break with a future version of Mac OS X. You'd also have to worry about the usability problem of users thinking the menu will close after making a selection.
You might consider writing you're own subclass of NSView to work like the menu button you're describing. After the user clicks on the button. You'll want to create a new NSWindow, with no border by using NSBorderlessWindowMask as the style mask. The content view of that window should be another custom view of yours that you implement the menu selection in.