Adding an NSTextField as a subview - objective-c

I'm trying to add an NSTextField as a subview of a custom view class I have (which subclasses NSView), and then make the NSTextField the first responder. This works fine. The text field shows up and I can start typing in it. However, any mouse events in the text field seem to fall through to its superview. For example, I can't see the mouse cursor when I hover over the text field, and when I click anywhere in the text field, it attempts to resign firstResponder status instead of letting me select text within the text field.
I'm not overriding hitTest or anything weird like that, and I only have one window, which is definitely the key window. Any ideas?
Thanks in advance! :-)

Related

UITextField losing focus after button press and text field switch (keyboard remains visible)

I've got a UITableViewCell subclass here that manages a UITextField setup on the right side of the table view cell. Anywhere from 4 to 8 of these cells are displayed at any given time depending on the table; I use them for unit data entry (ie, entering in distances, temperatures, etc) so there's quite a bit of logic bolted to the cell subclass.
For whatever reason, I've noticed that if I perform the following steps:
1) Tap on a text field to begin editing and bring up the keyboard
2) Enter in some text
3) Tap the clear button (which is enabled on the text field)
4) Tap on another textfield in the same table view
Then the current UITextField loses focus, but the second text field does not gain it. This means that no UITextField currently has focus, but the keyboard is still being displayed on-screen... but without any active text field, it does nothing, and cannot be dismissed (presumably because there's no first responder to resign?).
I can then tap on another text field again, and it will take focus and begin editing- at which point the keyboard becomes operable again and pressing the return/done key will dismiss it and end editing as usual.
If I simply tap on another UITextField without first hitting a button, then the second UITextField will gain focus immediately (as I'd expect it to). But it seems like button presses outside of the UITextField will cause this behaviour to occur if you try to switch fields after tapping any kind of button other than the text field.
Does anyone know what is causing this? It almost sounds like there's something wrong with the responder chain, but I'm not sure what the problem would be or how to fix it.
Firstly,you are sure the textfiled in the table has a unique identifier ,such as tag.
Secondly,you should make another textfiled become first responder if you want a textfiled lost first responder but the keyboard still appear.
Figured out what it was...
The problem was that I was reloading the table data in the delegate method that my custom cell was calling upon edit completion. Apparently reloading the tableview data while you're in the middle of switching UITextFields will cause the second text field to not gain focus (but the keyboard won't get dismissed), hence causing the issue I was seeing.

How can I create UIKeyboard with done button on top right corner?

I need to show UIKeyboard with done button on top right corner ..please look into attached image..any help would be appreciated.
This might help you. please check it out BSKeyboardControls
Create a UIToolbar keep two bar buttons in that. Initially Hide that toolbar.
Show the toolbar on the textfield didBeginEditing delegate of textfield
and hide the toolbar in didEndEditing delegate of textfield
EDIT: As prashant said BSKeyboard offers what i said. See the look and feel of it here http://www.cocoacontrols.com/platforms/ios/controls/bskeyboardcontrols
You should set inputAccessoryView propery of UITextField or UITextView to your custom view with all required buttons
#property(readwrite, retain) UIView *inputAccessoryView
Description
The custom accessory view to display when the text field becomes the
first responder The default value of this property is nil. Assigning a
view to this property causes that view to be displayed above the
standard system keyboard (or above the custom input view if one is
provided) when the text field becomes the first responder. For
example, you could use this property to attach a custom toolbar to the
keyboard.

UIPicker with UITextField

I made a research and all posts here are very blury regarding this issue.
I would like to use a UIPicker when pressing on a UITextField.
I would realy appriciate a step by step guide.
I tryd all posts here but every post gives me only a portion of what I need and I can't seem to connect it all together.
This is the last part of my application and i'm going crazy to finish it..
Thank you in advanced!
Gal
There is an inputAccessoryView property that contains a view that will appear instead of a keyboard on the bottom of the screen. Create a UIPicker, adjust its frame, provide values and assign it to the inputAccessoryView property.
UIPicker will appear when user taps on your UITextField.
If you don't need editing, you may use a UILabel instead of the UITextField. Solution is the same. I have a ready-made class if you need.
Here's a way:
http://www.youtube.com/watch?v=t_F1ex5opgA&t=14m10s
-(BOOL)textfieldShouldBeginEditing:(UITextField *)textField
where textField is the name of your text field.
Call your UIPickerView and return NO so that your picker is loaded rather than the keyboard.
The idea is to call an action that opens the UIPicker when the user taps the UITextField. Because the UITextField does not responde to the usual touchUpInside events that UIButtons respond to, I would just overlay a transparent UIButton on top of the UITextField and just in case, make the text field's userInteractionEnabled property NO. Hook the UIButton to responde to touchUpInside and call a method that opens the UIPicker. Another option would be an immediate response to the text field's touch by implementing "textFieldShouldBeginEditing" and immediately resigning the text field.
The next step would be to present the UIPicker - if we are talking about iPad, this would best be done by using a UIPopoverController. On iPhone, maybe consider bringing it up modally. When you create the view controller that holds this UIPicker, be sure to add a delegate property to it so that whatever value that was selected on the picker can be transfered back to the main view controller and on to the UITextField.
Hope this helps with getting you started.

NSSearchField as first responder

guys! I have a NSSearchField in a window's toolbar. I tell the window to set its first responder to the search field: it works. Now: if I ask the window to tell me what's its first responder, it is NOT the search field even if the search field has the focus...
Is there a way to set the search field as the window's first responder without having this mismatch?
Thank you
No. Or at least not easily. When a search field, or any simple text field, has keyboard focus, it isn't actually the first responder. When an instance of NSTextField (NSSearchField's superclass) is asked to become first responder, it asks the window for a "field editor", which is another text field used exclusively for editing. This editor is placed within the text field and set as the actual first responder.
To get the text field or search field, you could go up the view hierarchy using superview on the first responder. (I think it is the field editor's direct superview.) I'm pretty sure the actual text field is also set as the field editor's delegate, so you could also get it that way, but I don't remember where I read that.
More information about the field editor is available through the NSWindow class reference.

Getting UIPicker to appear when user selects a UITextField

I have a simple UITextField called month where I get users to simply enter the month they want via the keyboard that comes up. I would now like it for them to be able to use a UIPickerDate (or UIPicker) to make this selection instead. So when they press on the text field, a mini UIPicker appears and they make there selection, press anywhere on the screen and the picker disappears.
Does anyone know how to do this or has any suggestions? I am pretty new to programming and have looked at other answers but everyone seems to be referring to this being done in a table.
Thanks in advance!
You can set the inputView property on the UITextField to be an instance of UIDatePicker. When the instance of UITextField becomes the first responder, the picker view will be displayed with the standard keyboard animation.
// Assume that self.monthTextField and self.datePicker
// are properties of the view controller class
self.monthTextField.inputView = self.datePicker;
As for dismissing, that depends on the context. If there are more text fields to populate, consider adding a UIToolbar as the inputAccessoryView of self.monthTextField. Then you can add something like a UIBarButtonItem to make the next text field the first responder, similar to how the standard keyboard provides a Next button.