Cocoa Touch - trigger a selection table view from a textfield - iphone

Hihi all,
I have a TextField (the TextField is added into the TableViewCell from code) in my first view for gender selection. Would need to trigger a second view for gender selection upon clicking on the TextField. After selected a gender from the second view, the second view should be dismissed and the selected gender value should be returned back to the active TextField in the first view.
Hope that I am clear enough on my question. This might be just a foolish question, but I am still new in cocoa touch. Thanks in advance!
:)

If you are trying to get a selection of gender, then why is it a textbox? You could convert the selection itself directly into a text in code. Why display a text
box? Could you elaborate on what is it that you want to do. It is not so clear by your description.

Instead of create a second view for the gender selection, this is what I have implemented
When the gender textbox becomes first responder, in the textFieldShouldBeginEditing delegate, show up the gender pickerView in place of the original keyboard.
Upon selecting of a gender, in the pickerView didSelectRow delegate, return the selected gender to the active textbox.
:)

Related

Restrict the TAB key on accessory keyboards

I have a UIScrollView with 2 views, side by side, each of which covers the entire screen.
They are moved to visible bounds on user's action, only one covering the screen at a time. Both of these views have multiple UITextFields. Working with the simulator, I fill in a textField in the first view and when I press the Tab key, the firstResponder is assigned to a textField in the other view. I understand that on using the device, the user will not be able to do that. But what if the user uses a bluetooth keyboard, or similar accessory? I do not want a textField, that is currently not visible to become firstResponder. Can this be done?
EDIT: I just remembered the canBecomeFirstResponder method. But how do I determine which textField is about to becomeFirstResponder?
It sounds like the problem isn't that they shouldn't be able to tab between the two text fields, but instead that they shouldn't be able to edit a text field that isn't visible, and they should be able to tab between them if they are both visible at the same time.
Instead of restricting tab, I would implement the UITextField delegate method -textFieldShouldBeginEditing:, which allows you to return a boolean whether or not that text field should become the first responder.
Something such as:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
// Only edit if the text field is visible
return !textField.isHidden;
}
You may need to adjust this code to fit your 'is visible' status of the text field.

How to make a contact field entry like this on iOS?

I have an application in which when tapping a button it will show a view to the user to enter the contact number of the user, like in the image below. Can anybody help me achieve this? I need my users to chose their country within the flags and corresponding stdcodes needs to be there
What I see in the example: a UIImageView for the country flag, a UILabel for the country code and a UITextField with a placeholder for the phone number. You can set de value for placeholder in IB or programmatically.
You will have to create a custom view for that.
Steps to do it:
Derive a class from UIView.
Add UIImageView, UILabel and UITextField into it.
Layout it properly.
On button click, show this view with proper frames/bounds.
Create a view like whatever you have shown and initially make it hidden, when user click on the button make the view visible.
ON action event add this sub view into your view
In Xib file,click the label and see the right side properties,In that properties you will find the placeholder option.In that placeholder,type the text you want.That text will be appeared as a hint for the user when he taps it.Or otherwise,directly in your code where you declare the label,in that label code
label.placeholder=#"Enter Contact here";

Hiding PickerView and Box To Show What Was Selected

I am working on implementing something in my iOS app that I see in mobile websites all the time. I would like to have a TextBox or TextField of some kind that shows what value is currently selected. When clicked, it will present a UIPickerView with a list of possible choices. Upon selection, the UIPickerView will disappear, and the TextBox or TextField would get updated with the selection the user made. Can someone point me in a good direction for doing this?
You can save indexPath value in a string and show it on textfield like: [textField setText:NSString];

get cursor on textfield

I need to get the cursor in textfiled but on the textfileddidbeginEditing i have to open the picker view for selection , so for that reason i need to resignFirtsresponder to the textfield ,inorder that picker view is visible .But by doing this the cursor gets disabled as i open the picker (and the keyboard gets hide by resignFirst responder).I want to show the cursor as because when user cliks on partilcuar textfield so by that cursor he can track on which textfield he is making the selection.
Hope i am clear with my question.
if you want the picker instead of keyboard, set the text fields inputView as the picker... so when you tap the text field the picker will pop up like keyboard and the textfield will show the cursor too.. no need to dismiss the keyboard and then show the picker..
If I understand your problem right, this is just an usability problem. I think you can solve this if you just add some other mechanism for showing the user which textfield is in editing-mode.
For example add an text-color to the TextField. If the user disable the UIPickerView set the text-color back to the normal state.

How can I show a UIDatePicker instead of a keyboard when a user selects a UITextField?

I have a nice clean UI within a table view which has a few text fields for the user to fill out. One of the fields is for the user's birthday.
I'd like to have it so that when the user selects the birthday field, a view containing a UIDatePicker would come up as, just like the different keyboards do when selecting a text field.
Can this be done? I would have to prevent the text field from being the first responder (to avoid having the keyboard come up) and I would have to animate the view sliding up if no keyboard was showing before.
Would presenting the view modally be an option? If so how would I go about doing it? From the documentation it seems that modal views still take up the whole screen, I just want to use the lower 216 pixels (height of the keyboard and UIDatePicker).
Any one have any tips on how to go about doing this?
Old question but the correct way to do this these days would be to set the UITextField's inputView to a picker you created somewhere. Something like this:
UIPickerView *myPicker = [[UIPickerView alloc] init];
// set picker frame, options, etc...
// N.B. origin for the picker's frame should be 0,0
[myTextField setInputView:myPicker];
When you go to edit a UITextField, iOS really just displays whatever view is at textField.inputView which by default is the keyboard, you can make it anything you want as long as it's a subclass of UIView.
Regarding animation, take a look at DateCell sample application -
http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html
And in any case, the proper way to do this is set UITextField's inputView to show the picker instead of the keyboard. That's what it's meant to do. More on that here:
How can I present a picker view just like the keyboard does?
Cheers,
Oded.
I would implement this by just animating a view containing the UIDatePicker, a Done, and Cancel button) up from the bottom of the screen. Using CoreAnimation, this should be pretty easy.
Why are you using a text field if you don't want to accept user input from a keyboard? Instead use a UILabel subclass (where you override the touchesBegan/Ended:withEvent: set of methods to show the UIDatePicker) or a UIButton (where your action is a method which slides up the UIDatePicker).