iOS - IBAction - in which text field the user is typing - iphone

I have 2 text fields in my app and both are connected with my "devTyping" IBAction.
This method (I guess it is a method) will be called when the event "editing changed" happens.
How can I tell my method, in which text field the user is typing?
- (IBAction)devTyping {
NSLog(#"How to know in which text field the user is typing?");
}

Take a look at this question, which should be an equivalent as to what you are asking :)

You could declare the method like this:
- (IBAction)devTyping:(UITextField*)sender {
NSLog(#"The user is typing in text field %d",sender.tag);
}
And assign each textfield a tag in Interface Builder, which is just a number to identify the text field (or any other element).

Related

Edit Name of cell upon tap - Swift

I want to edit the text in a cell by tapping and I was wondering if there is a way to do it other than by adding a text field. is there something in the table view delegate that I missed?
You can create cell (or any other UIResponder subclass) that conforms UITextInput protocol (or maybe UIKeyInput is enough). Here is simple example (old link)
Notice,
you should set cell.canBecomeFirstResponder = true.
To show keyboard use cell.becomeFirstResponder()
Maybe there something else, that you should do. I recommend reading docs.
...Or use UITextField :)
We use an array to display no of text label in cell.
so you can do is, you can use a text field and a button on a view.
In button action add a line of code like stringArray[2] = "new string" to replace the particular element from array and when you enter a text and press a button the element will get replaced and just reload the table view.
And you can also write the method in didSelectRowAtIndexPath, write stringArray[indexPath.row] = "new string" and reload the table view and it is done.

How to know which tableview cell's text field is changed its content

I have a tableview with around 100 text fields inside it. I added only one text field. It is reused and it is accessed using tag.
The problem is this: suppose the user has changed some textfield. Now, I want to access that text field changes during saving of the data.
How can I do this?
You are very near to your goal. You have already assigned tag to your UITextField. You can use and track tag in this delegate method.
-(void)textFieldDidEndEditing:(UITextField *)textField
{
}
First set tag of textfield with indexpath.row
- (void)textFieldDidEndEditing:(UITextField *)textField
{
// replace text in your array
}

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.

UITextField SecureTextEntry field changes the keypad from numberpad to generic keypad

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.

How to get current value of UITextField in cocos2d 0.8.2?

Hi all I am using cocos2d 0.8.2 for my new game. I have added a UITextField in my game and on click of a button (this button is actually a sprite i m using ccTouchesEnded! ) i save text field's value in database, but whenever i access the value i am getting nil. if i initialize the textfield value by some string, it always give me only that value.
i.e.
[txtField setText:#"Enter Your Name"];
when i access the value of txtField on a click of button it always give me "Enter Your Name". Although the value is changing when i type in textField, but its not returning me the new value.
is this a issue with cocos2d 0.8.2 or i am missing something?
You don't save the entered text. You just set #"Enter your Name" as default text, that is displayed in the cell. You should have a look at the UITextFieldDelegate methods. You have to overwrite the method didEndEditing, that is called after your editing or typing in text has ended, and implement there a line that saves the current value. Here you can use something like this:
NSString *containerForTextFieldValue = textField.text;