Popup UIPicker when tapping on UITextField - uitextfield

I need to display/show a Picker when a user taps on a textfield, I mean, it should appear a picker instead of a keyboard. Also, some sort of "done" button above the picker so the user clicks on it and the value from the picker is copied to the textfield and the picker is hidden again.
I've checked many tutorials from the web but haven't found anyone that can really help me.
I found a tutorial that pointed me in the right direction but I'm still missing to disappear the keyboard when clicking on the textfield.
Dismissing UIPickerView with Done button on UIToolBar by #slev
Any ideas?

If you're not targeting iOS versions older than 3.2, it's easy. You can either assign the UIPickerView as the inputView property of the UITextField and the UIToolbar containing the 'done' button as the inputAccessoryView, or you could make a single UIView that has both the picker and the toolbar as subviews and assign that as the intputView (and leave inputAccessoryView as nil). Either way, this will animate your picker in in place of the normal keyboard when the text field is activated.
More details on this are available in the documentation.

Related

Using UIDatePicker inline style in popover - avoiding keyboard

I am using the new UIDatePicker 'inline' style in iOS14, and I want to show the picker inside a popover, like I did before in iOS13. I manage to do this fine, but the problem happens when you select the 'time' picker which brings up the keyboard, causing the date picker to get squished.
I'm not sure how I can avoid this happening. I've tried:
scrolling the presenting view controller's tableview to the top, and added a contentInset
setting a height constraint for the UIDatePicker control
listening to keyboard notifications, which get triggered but not sure what to do with it
Is there anything else I can try to get it to work correctly? Would love some ideas on potential solutions.

How to add tooltips to NSButtonCell that is within a NSMatrix

I am currently instantiating an NSMatrix w/ NSButtonCell subclasses through IB
I use the identity inspector to change the Tool Tip property
But the tooltip doesn't show on the button cell.
If I set a tooltip on the NSMatrix object, a tooltip still doesn't show
If I add an NSButton to the same view, and add a tooltip to that, it does show
Why won't my tooltips on NSMatrix or NSButtonCell show?
I don't know why it can not be set in the Interface Builder (It seems like a long standing issue), but you can set them at least programmatically.
[self.matrix setToolTip:#"Tooltip for first item" forCell:[self.matrix cellAtRow:0 column:0]];
[self.matrix setToolTip:#"Tooltip for second item" forCell:[self.matrix cellAtRow:1 column:0]];
Careful, if in InterfaceBuilder you click the button, you can add the tooltip to the button, and the class displayed under "Custom Class", top right, is NSButton. But, if you click the button again, as you do while selecting stuff in xcode, what is selected is the NSButtonCell, which appears to have a separate tooltip. If you're not careful you add your tooltip to the NSButtonCell instead of the NSButton, and it won't show in your running application.
So, the problem may be that you have clicked the button one more time in IB, and you thought to enter the tooltip for the NSButton, but you didn't.
Personally I think it may be a bug, why would you want to add a tooltip for the button cell?

Create Back Button with Storyboards

I currently have 3 tabs connected to a common UITabBarController. When one of the tabs is selected the user is taken to a UITableView with 3 cells which can be selected. When a cell is selected the user is taken to a new page with a UINavigationBar at the top. My understanding is that the UINavigationBar is supposed to include some sort of back button and I couldn't figure out how to enable it.
In place of the default back button, I dragged a UIButton to the corner and connected it to the 'Show Detail' property of the previous view but when I press the UIButton I am taken to the right UITableView but the tabs are missing for navigation. What am I doing wrong? My segues look like this:
The UINavigationController has the back functionality. How to go back one view in UINavigationController?.
Here is some old tutorial on how to combine that with a tabbarcontroller. should still be the same principles.

How to make UIPickerView that appears if i click on the UITextField?

How can i make a UIPickerView that appears when i select a TextField, and the input of this comes into TextField if i select a value of UIPickerView?
How to do this? Have you an example of this?
Create the UIPickerView and set it as the inputView of your text field. It will then be animated on screen for you when you start editing the text field. The picker view delegate methods can be used to update the text field's value.
You will also want to create a toolbar with a done button and set this as the inputAccessoryView - this will allow you to dismiss the picker when you have selected your value. Again, this will appear automatically above the picker view when the text field begins editing.
Please take a look at this example http://www.techotopia.com/index.php/An_iOS_4_iPhone_UIPickerView_Example
You can initially hide the picker by
picker.hidden=YES; in your viewdidload method and for showing it when touch on the textfield you can write picker.hidden=NO; inside uitextfielddidstartediting method. Thanks.

IPad Textfield DropDown with PopOver Control

Im wanting to create a generic dropdown control for my IPad app. Basically when the user clicks on a textfield a popover control will show and list items. The users can keep typing in the textfield which will filter the items in the dropdown popover control.
Has anyone got any advice or know of any examples on accomplishing this?
Basically it will be like the "Suggestions" popover list in the App store search field of the ipad.
Thanks in advance
Well, I would accomplish this by loading a TableViewController into the PopoverController and make its interface available to the ViewController (the one that has the textfield in it).
In the TableViewController I would load a dictionary/array of items. Whenever a user enters text in the textfield (you can respond on this trough events in your Interface Builder) I would then call a function in the TableViewController that updates the list that is displayed (e.g. displays all dictionary items that start with the entered text).
Whenever someone clicks on a item in TableViewController, you can then call a function in the ViewController.
I can't give you a code sample, since that would require quite some time to create :P.
I hope this helps you.

Resources