UIPickerView - Selects row too fast - iphone

I am currently using a UIPIckerView in my app to allow a user to select from a list of options. The problem is that there isn't enough of a delay when the user stops spinning the wheel and it is selecting a value before the user has a chance to scroll further down the list.
Is there a way to override the default behavior that selects the row as soon as the wheel stops spinning and the user removes their finger? I see Mobile Safari includes a "Done" button which would be great.
I can provide code if necessary (not sure how it would help).
Thanks!

You can add this manually; just add a done button to the view that holds the UIPicker, and have IT do whatever action you're currently performing in – pickerView:didSelectRow:inComponent:.

The UIPickerView automatically selects which ever row stops in the center. It does not work like a table but more like a popup menu. As such, you can't use a picker view like a button to call an action because it will trigger the moment the user stops moving it whether that represents their final choice or not.
Instead, as noted previously, you need a second control element (usually a button) to call the action that makes use of the pickerview's selection.

Related

Select the first element in view for Voice Over

I am using Xcode to make an iOS app. When I segue into the next view controller, it has objects in the following order from top to bottom on the screen: label, collection view, button. When I use voiceover, I want the first item on the screen to be in focus (the label). However, whatever I do, it is always a particular cell from the collection view that is selected by default (somewhere in the middle of the screen). In landscape it is a different cell and in portrait a different cell. But every time it is that same cell. I tried using UIAccessibilityPostNotification, as well as using delays and other things. Nothing seems to work.
Should be posted when a new view appears that encompasses a major portion of the screen.
Optionally, pass the element that VoiceOver should move to after processing the notification.
UIKIT_EXTERN UIAccessibilityNotifications
UIAccessibilityScreenChangedNotification;
You need to provide
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, youLabel);

Hide keyboard plus return key?

I have a view with a textfield at the top, a textview under it and two buttons below the textview.
The keyboard is configured with a "Done" button. Once the user has typed in their info, they click the save button, which is below the textview. First they click Done to hide the keyboard (and reveal the save button) then click the save button.
I need to allow carriage returns in the textview but "Return" is already taken up by Done.
How is it usually handled when you need a Return key and ability to also hide the keyboard?
Drag a button into your view, delete the text, and resize it to take up the entire view. In the document outline, select the new button and drag it to the top of the list of elements. This puts it in the background so it is not hiding the elements of your view.
Add this code to your ViewController:
#IBAction func hideKeyboard(sender: AnyObject) {
self.textField.resignFirstResponder()
}
Link the button to this action and you're all set.
If you're using a UINavigationBar or have other buttons or fields, activating any of those UIControls could be detected and used to dismiss the keyboard via resignFirstResponder(). In fact Save/Cancel/Done are UIBarButtonItems and are a standard mechanism for completing things and changing state, and create a framework for accomplishing what you want. If you don't take that approach then you have to get creative with how you do it, and also make it clear to the user what needs to be done.
In Interface Builder you can change the type of your main view from UIView to UIControl and then use addTarget() to detect touch events as a 'touch outside' area and use those actions to resign first responder as well. But you might want to consider a UINavigationBar or some other button bar or tab interface to make state transitions.
Also review iOS Human Interface Guidelines document. It's a great document for understanding how iOS is designed to handle common situations like what you are dealing with, and it can get you out of design ruts. It's well written and worth re-visiting periodically.

Adding a button to last UITableView row

I'm developing an app where the user can choose between a number of included songs. I also want the user to be able to choose a song from his/her iPod Library.
Currently the song is choosen by selecting it in a UITableView. So I figure I would like to add a new row at the end of the table and make it a button that will fire a MPMediaPickerController. All songs are placed in an array consisting of their names.
My question is how I add this last row? And also how I can "save" the selected song (or the path to it) to be used in the parent viewcontroller?
Well, you can use the UITableViewCell directly as a button itself, so when a user clicks on the last row, the action is being executed. But if I understand you right, you want to add a specific extra button as a subview of a UITableViewCell. That means if the cell (the last row) is being built, you compose your button, add its target and action, and add the button just as simple subview of the cell.
Well, the parent should now receive the message that the button has been pushed. I would do this using NSNotification, that is very easy to use, just check out the Apple documentation and take a look at an example. You can even send the selected song or its name path via the notification directly to the parent controller, where you can handle this notification.

iphone - forcing button to acknowledge touch programmatically

When you touch a UIButton it hides for a fraction of second and then it executes its action. This fast "blink" is the feedback the user needs to know that the button has been clicked.
In the project I am doing, I need to select the button programmatically, as if the user had clicked it. In other words, the same behavior has the button had been clicked by the user... a fast blink and execution of its action.
Is this possible to do?
thanks for any help.
The change in the appearance of the button is effected by setting the button's highlighted property. The property is automatically set to YES when the user touches down on the button, and back to NO when she releases.
The highlighted property is writable, so you can set it YES yourself to simulate a touch down. You'll probably want to use +[NSTimer scheduledTimerWithTimeInterval:invocation:repeats:] to set it back to NO after a short interval.
It is pretty simple, and probably there is a better solution.
First, use images to your button, and when you have to fire the button, you just change the button's image in the normal state to the pressed image, and after that, replace it back to the original. You can simply do it with a timer.

UIPickerView row selection

I have a UIPickerView with two components.
It works fine when the user scrolls each component until it reaches the desired value.
But I want it to behave like the picker in the calendar or the clock apps. Meaning: When the user presses a certain value in one of the components, I want that component to automatically turn that row to be the selected row (so the user doesn't always have to scroll, he/she can also simply select the value they want).
Does anyone know how to do that?
Thank you,
~Chonch
It is standard picker behaviour and it should work so automatically.
If your picker does not select tapped row automatically try to set userInteractionEnabled property to NO for the view you return from viewForRow: method in picker data source.