keep contents of textview till a button is pressed - ios

I have been looking for a code to keep the contents of the textview ,till i click on a back button or a done button on the same page. But when i gave the code:
(void)textViewDidBeginEditing:(UITextView *)textView{
myTextView.text = nil;
}
Every time(even before completing the text) , if i press the return button of keyboard and click on text view again to type the rest, the already existed text clears away.
I have kept the above code for clearing the default text "Enter your text", when the textview is shown for the first time.
I have been working by setting booleans, but could't get the result! Please if someone could clear me out of this . Thanks in advance.

Do it like this
(void)textViewDidBeginEditing:(UITextView *)textView{
if ([myTextView isEqualToString:#"Enter your text"]) {
myTextView.text = nil;
}
}
This code will check that is your text is equal to Enter your text and if it is than it will clear otherwise not.

Related

UI automation clear textfield with the "Clear button"

Is there a way in UIAutomation to tap on the "Clear text" button of a textfield? Can you add an accessibility identifier to it, or does it already have one?
At this moment I can only tap on the delete button of the keyboard or replace the textfield with an empty string. But I'd like to be able to tap on the clear text button that's being shown in my textfield.
Already found something in a comment of this issue:
textField.buttons["Clear text"].tap()
But this doesn't seem to work for me: "No matches found for this button"
You need to tap the text field first, so the button is visible:
let textField = app.textFields["Fanta"] // or however you're matching it
textField.tap()
textField.buttons["Clear text"].tap()
This works for me as a minimal example.
Try this one, it help you:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
textField.text = #"";
}

How to program the Enter button to allow two actions, either correct or wrong?

I'm creating a word game,
I need my Check/Enter button to do three functions.
Correct = if the right word is correct then the button should make the custom keyboard disappear.
Wrong = if the answer is wrong the keyboard should remain on screen.
- (IBAction)btncheck:(id)sender {
}
Your question is a little too broad but all you need is add a check to your IBAction.
- (IBAction)btncheck:(id)sender {
if(isValid){
//correct
[self.textfield resignFirstResponder];
}else{
//Wrong
}
}

How to move to next screen on click of Read only text field iOS

I have a textfield that is readonly. I have another Search View Controller(VC) also. My aim is when the user clicks on readonly textfield it should open the searchVC. I tried attaching Push seque to SearchVC but it's not working. Tried same with a button and works seamlessly.
Pls suggest whats the approach for this.
You can use gesture to your textfield
or
You can use custom button above the textfield. You have to show/hide the button on textfield disabled/enabled
try this
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField.tag==1)
{
//write alert view to check "click on this text filed alert is appearing"
return NO;
}
else if (textField.tag==2)
{
//it's behave normal uitextfiled
return YES;
}
}

how to make the textfiled clear on click

i have app i want that when user enters any data and text field has by default 10 so when user click on textfield then it clear the textfield to enter data.It mean when user enters data it doest not delete one bye one like clear 1 and o with back space but by default when user click textfield it should get clear.
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[textfield settext:#""];
}
if you focus on textfield then this method is called and textfield is cleared.
Apple Developers already did this for you, set the 10 into UITextField placeholder property see doc, when you tap on the textfield, it will be remove automatically!
However, if you want to clear it in case you've added 10 as text of textfield then,
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
textField.text = #"";
}
It will call each time when you focus to textfield.

Clearing text on UITextView while begin edit

On a UIViewController I have placed an editable UITextView with some text to be displayed while loading say "Some comment". My requirement is that when I click inside the text view, the pre-defined text should get cleared i.e. the text view should be blank and should no more show "Some Comment" text on it.
I used textViewDidBeginEditing as follows, but is not hitting the method itself:
- (void)textViewDidBeginEditing:(UITextView *)textView
{
textView.text = #"";
}
Do I need to raise any events for this or I need to define anything else for making the program to hit that method when the user clicks inside the text view.
Thanks!!
Set the delegate for the UITextView inside the .Xib File by connecting it to the File's Owner.
myTextView.delegate = self;

Resources