Drop down selection with UIPicker performance - ios

I wanted to use a UIPicker to simulate a drop-down menu and I found this code. It`s the second answer.
UIPickerView select and hide
Its exactly what I was locking for except for one thing. When I tap my TextField activating the method, like the author sais i should do, it takes a while for the UIPicker to show up. I would like to know if theres a way to make the code faster.
I think this happens because the method creates a UIPicker every time, but I`m not sure. Sorry if it is a stupid question.
Thanks

What I have done in the past is create the UIPickerView as a property of my UIViewController and then use the hidden property to display and dismiss it. You could even animate it up and down if you wanted to rather than just hide it. This way you will not be creating it every time. I could see how the creation would take a while if you are having to set it up with a lot of data or pulling the data from somewhere else.
So if I was you, I'd create it in viewDidLoad and then hide it until you are ready to use it instead of creating it each time. Or use an animation to take it on and off the screen.
One thing to remember, you are using the same UIPickerView each time, so you may want to set it up to some sort of default each time before you display it so it isn't just equal to whatever value they put in last upon display.
Likewise, I would create the toolbar and save it as a property as well and just hide or display both of them at the same time.

Related

How to completely reset a UITableViewController while still on screen

In my app, I have a very custom UITableView. The cells are all statically defined in Interface Builder, but based on the data structure the table morphs in many various ways. For example, if some data doesn't exist, some cells (or entire sections) are not displayed, custom separator lines are added to account for missing cells, extra views are loaded into the cells, VoiceOver labels change, etc. Because all the cells are static, I set up the table layout in viewDidLoad because I always have the data available at that time. I have always presented this view controller modally, which has worked great. If the user wants to display different data in this table they have to dismiss the view controller and pick a different item to present it again, and it gets rendered appropriately in all cases.
But now I am converting this into a split view controller for iPad, so this UITableViewController never disappears off screen, but I need to set up the table again when the user taps an item. The problem is, because the table is never deallocated, its previous layout still exists when I load more data into it. It would be a lot of work (and an excellent opportunity for many difficult to reproduce bugs to pop up) to test all possible scenarios and try to reset it back to its "pre viewDidLoad state" or undo those previous layout changes if not relevant anymore, if not impossible because I don't have references to the many different custom separator lines generated.
My question is, is it possible to completely reset the table view controller every time a row is selected in the master view controller, therefore allowing it to properly set up the layout because it is not stuck with the previous layout?
I essentially need some way to completely wipe it clean as if it never did any setup, then instantiate it again to cause viewDidLoad get called (or I can move that code to its own method or viewWillAppear). I'm basically looking for a way to reset the tableView back to how it is defined in Interface Builder.
I believe this would result in a flash because the table would completely disappear then reappear in a different format, but that would be acceptable. If that can be animated that'd be nice. If this is really not recommended at all, how do you suggest I proceed to ensure the layout is always appropriate for the data it is presenting?
I was over-thinking this. There's really no need to completely throw away the table and generate a new one. It turned out to be simpler than I had thought to reset the table back to its default state. Just had to be sure to catch every possible thing that could change, including VoiceOver labels, and reset to nil or the default value. Then it can run through the reset code then the layout code every time the data changes and render an appropriate layout. The most difficult part was to remove the custom separator lines, which I solved by adding each one to an array when it's created, then index through it and remove each one from its superview then remove the Autolayout constraints associated with it. One can wrap all of this into a UIView animation block to get a nice fading effect. It's working quite well.

tab button to change focus from one text field to other using bluetooth keyboard on iPad

I have a module to be developed where i need to tab on my form textfields using bluetooth keyboard. But it doesn't seem to work. the method textfieldshouldbeginEditing gets called multiple times as many times as the number of text fields on the xib. Can you please help as to how to change the responder once i get the tag of selected field. I have my text fields in an array. tried using that but it continuously loops in that method.
Dealing with tabs within your views is a non-trivial task. At a high level, UIKit will check every visible field within the view once to determine which fields could be tabbed into, then it will check the "next" field a second time. You will need to keep track of which fields have been checked, and what order you want the tab to proceed in if you want to deal with this issue.
Please see this blog post for a great explanation.

Is there a way to watch for a selection to change in UITableView?

I have a UITableViewController that comes on to the screen in a popup. Basically it slides in from the left and shows the hierarchy available.
When it comes on screen, I select an item within it to represent the current location. Before today, this all worked.
Today I added a UITextView as a header to the table. Since then, my selection is acting strangely. When the UITableViewController appears, I can see my selected row get selected briefly, but it immediately becomes unselected. Calls to indexPathForSelectedRow return nil.
Is there a way to be alerted whenever the selection changes in UITableView? I know to use tableView:didSelectRowAtIndexPath: to keep track of when the user selects an item, but this problem is happening without user input. I'm assuming I've done something incorrect within the code, but I'm trying to track it down without posting all my code here.
Edit
Apropos of nothing, I did find that the problem goes away if I remove the Navigation Controller that I had added to the UITableViewController. This was because I had not set the property clearsSelectionOnViewWillAppear to NO. By adding the Navigation Controller, the UITableViewController was getting loaded differently, causing the property to actually be used.
However, I still would like to know how to be alerted to table view selection changes.

how to connect textfield with table view of listed options instead of keypad

I need to be able to disable the keypad in a textfield, and instead when the user taps on it to start editing, a new table view will appear presenting a list of possible strings with which the textfield should be filled.
Anyone has any suggestions on how to achieve this?
Thanks in advance
p.s. I tried already but this functionality cannot be nicely implemented with a picker in my case, as there are too many options to choose from and (more importantly) each one of them is a rather long string and cannot appear entirely in a picker.
I believe you just need a regular cell that, when tapped, pushes a new detail UITableViewController with all the options to choose from. Once an option is chosen, set the cell's textLabel to whatever option have been selected.
If you'd like to go for an easier path, then you should also probably check the free Sensible TableView framework, as it has these kinds of cells out of the box (called selection cells). You just pass on your strings array to the selection cell and it will automatically display the detail view, and even assign the selected option to one of your object's properties if you wish. Should save you some good amount of manual work. Good luck!

Implement auto-completion on iPad

Scenario: I have a list of medication (stored somewhere, let's say an NSArray).
There is a UITextField where a user can enter a medication to get more information about it (or whatever).
I want to suggest word completions while he is typing (but that is rather easy).
Where is the best place to show these suggestions? Since it's on the iPad i want it kinda like when you google and you get your suggestions right below the search bar. Is that possible on the iPad? A table that lays over the rest of the screen, placed below the text field? Like a pop up or something? I have never really used an iPad in my life before, therefore I don't know what the iOS way would be..
Edit: Something like this but connected to a textfield and not a button or whatever that thing is:
Edit: Or even better: Something like this but for iPad and not Android:
In my app I used a UITableView for displaying the suggestion.
I added the tableView above my UITextField. When there is no auto complete word found, I hide the tableView.
Please check my autocomplete implemetation.
Check out my control, MLPAutoCompleteTextField for iOS. It is a subclass of UITextField that does autocomplete.
The implementation is similar to what you are looking for in the second screenshot, and very customizable.

Resources