How i can fetch what is typed between 2 UITextViews on iphone? - 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.

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.

Access UITextField with tag on a static Table

So I have a static TableView setup in the interface builder with multiple sections, labels, and text fields.
I'd like to be able to something along the lines of
[self.view viewWithTag:kNameTextfield]
and get the UITextField with that tag that I've set.
For some reason I cannot access the UITextField and it comes up Nil. I imagine because it's somewhat deeply nested? I thought about creating an Outlet collection of all the text fields and other than iterating through them every single time I need to change something seems like a waste?
What I'm trying to do is on initial load, it populates the values of the textfield by values in a dictionary. So it's useful to be able to target a specific textfield.
Try iterating through the subviews:
for (UIView* viewsLevel1 in [cell.contentView subviews])
{
for (UIView* viewsLevel2 in viewsLevel1)
{
UITextField *textField = [viewsLevel2 viewWithTag:kNameTextField];
}
}
Go as far deep as you need to go

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
}

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.

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

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).