UITextField SecureTextEntry field changes the keypad from numberpad to generic keypad - iphone

I have a textField created in IB. I have set the keypad type to Numeric Pad in IB.
When i make secureTextEntry = YES in -(void)textFieldDidBeginEditing:(UITextField *)textField method , my keypad changes from numberpad to generic keypad. I even tried to make the keypad to be numeric programatically but still it doesnot changes.
I have set it like this
-(void)textFieldDidBeginEditing:(UITextField *)textField{
if(textField == self.activationCodeTextField){
self.activationCodeTextField.secureTextEntry = YES;
self.activationCodeTextField.keyboardType = UIKeyboardTypeNumberPad;
}
}
FYI,
I cannot set the textField to be secure in IB because i have an hint text like "4-digits" displayed to the user in the textfield till he starts typing in the text filed. Once he starts typing in the textfield, i want the entries to be a secure text so that it displays only * instead of actual characters he types.
Can you please let me know whats wrong in what I am doing?
I also have two more query
I have a textField where i have some default text (like hint text). I want this hint text to be displayed to the user till the moment he starts typing. I dont want to clear this text when the user clicks on the textfield and then the default text clears away. but, i want this text to be displayed till the moment he actually starts to type something on the keypad, then the default must be cleared and then the actual typed in text to be displayed on the textfield. IS it possible to acheive this ?
Is it possible to set the cursor position of textfield to the first character programatically. This is needed because, i have some default text (hint text) and the cursor is at end of the text. I want the cursor to be at the start of the text. How to make this possible programatically?

Have you tried using -setPlaceholder: on your UITextField? That way you wouldn't need to do put text in the text field, and then later manually convert it to be secure. e.g.
- (void)viewDidLoad {
...
[textField setSecureTextEntry:YES];
[textField setPlaceholder:#"4-digits"];
...
}
That will completely take care of your last two questions. Regarding the first, though, I'm not sure if you can have a numeric keyboard for a secure UITextField or not. It would seem that you can't if setting it programmatically has no effect.

Related

which delegate method will call click on back space button in keyboard

I have text field in that i have to some functionality click on back space button in keyboard when the text field is empty ...shouldChangeCharactersInRange is calling when the textfield has some text.how call solve this problem.
You can catch that key in
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
It is not written explicitly in the docs but if you press the backspace key then the last parameter string will have a length of 0.
At least this worked for me when using UITextView objects.
Hope this helps :)
You should read the documentation of UITextField... By the way here it is from the documentation of UITextField
textFieldShouldClear:
Asks the delegate if the text field’s current contents should be removed.
- (BOOL)textFieldShouldClear:(UITextField *)textField
Parameters
textField
The text field containing the text.
Return Value
YES if the text field’s contents should be cleared; otherwise, NO.
Discussion
The text field calls this method in response to the user pressing the built-in clear button. (This button is not shown by default but can be enabled by changing the value in the clearButtonMode property of the text field.) This method is also called when editing begins and the clearsOnBeginEditing property of the text field is set to YES.
Implementation of this method by the delegate is optional. If it is not present, the text is cleared as if this method had returned YES.
Availability
Available in iOS 2.0 and later.
Declared In
UITextField.h
If the text field is or becomes empty, put a space character in it. If you detect a backspace, and the dummy space character is the only thing in the text field, don't delete it (yet). When finally reading out the contents of the text field, remove the spurious leading space if you added one.

How i can fetch what is typed between 2 UITextViews on iphone?

i have two UITextView items, how can i fetch what is written using a button on iphone?
Imagine something like a translate app, the user enters a word in UITextView 1 and by pressing the button the UITextView 2 is getting filled with data.
UITextView has a property text. Simply use this.
Set up IBOutlets for textView1 and textView2. Then have the button do something along these lines:
-(IBAction)moveTextOver:(id)sender {
[textView2 setText:textView1.text];
}
To get fancier, you can have a method -(NSString *)transformText:(NSString *)text that translates or does whatever you like. Then use
-(IBAction)moveTextOver:(id)sender {
[textView2 setText:[self transformText:textView1.text]];
}
Create an IBAction method that is linked to a button and in that method read the "text" property of the textView or textField, do your calculations on it and assign the results to the text property of thee second field.

saving text data from UITextField without pressing additional key (help needed)

I am new to iPhone programming. I am working with UITextField and UITextFieldDelegate. I have five textfields. I am trying to input data in them using numberPad keyboard. And the data should be 1 digit long. After that hitting another key should take it to the next textField. I have implemented it all but the only problem is when all 5 textfields are filled, I have to press keyboard 6th time to save the text data of fifth textField, Is there any way I could save the text data of 5th textfield without pressing any key on the keyboard 6th time?
Any help or suggestions are welcomed.
Thanks
Vik
You can use textFieldDidChange delegate Method for 5th TextField and compare it like this.
if (textField==textField5 && [textField length]>0){
[textField resignFirstResponder];
}
I hope this will help.
Im assuming that you are using UITextFieldDelegate method to move to next text field. You can keep a count on how many text fields are entered and keep checking it:
if(count == num_of_textfields)
{
[textField resignFirstResponder];
//Call your method to process the input here.
}

Can I not remove the return key on the keyboard? Or at least change its text to "Set"?

I am creating a sign up page for my iphone app and am having some problems making the way the input views work for the different kinds of fields consistent. The fields are listed as cells in a table view and the editing is supposed to take place directly in the table by having appropriate input views sliding up from the bottom.
Let me focus on only two of the fields here, namely the username field and the birthday field: for the username field it makes sense to have an ASCII capable keyboard sliding up when the user presses the field whereas a date picker seems more useful in the birthday field case.
For both the keyboard and the date picker the cancel button could be located in a tool bar just above the input view. But what about the set button? If I put that in the toolbar as well I need the return key in the keyboard to go away! But that is not possible is it?
If the return key cannot be removed then I might have to live with the set button in the toolbar only in the birthday case and then use the return key as the set button in the username case - but can I then at least change the text on the return key to "Set"?
No it's not possible* to hide the "Return" key.
It is not possible to set the string to "Set" either, but could use the .returnKeyType property to change it to a limited set of strings.
theTextField.returnKeyType = UIReturnKeyDone;
(* Well you could put an opaque UIView directly above it but it's a very bad practice and generally breaks if the user chooses a different input method)

Limit number of characters in UITextField where input is from UI

I have a UITextField for which I get input from some buttons that are part of the UI (so the input does not come form the phone's virtual keyboard). I want to limit that number of characters. I tried using the shouldChangeCharactersInRange, but it only works if the input comes form the virtual keyboard, and it doesn't work if the input comes from the buttons on the UI. Is there anyway I can solve this without programmatically having to count the characters in the text field every time I want to update it?
Thank you,
Mihai Fonoage
Implement the UITextField Delegate method shouldChangeCharactersInRange:
set the method to return YES when the length of the string is less than your maximum count.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField.text.length<3) {
return YES;
}
return NO;
}
Since you are programmatically making changes to the UITextField once the user clicks the relevant buttons on the UI, you should keep track of the number of characters entered using a counter.
Increase the value of the counter every time a relevant UI button is touched. Update the textfield only if the counter value is <= maximum allowed no. of characters.
Check the length of the string property on the textField before accepting changes.
There is a textRectForBounds Property