UI automation clear textfield with the "Clear button" - ios

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 = #"";
}

Related

How to set cursor to text field when I touch button on AlertView

I've an issue need to help.
My issue is: I have 3 text field in view. Currently, the cursor put at text field (3). The user can touch done button on the keyboard. When done button I've checked format valid. Assume, text field 2 is not valid format type (show uialertview), when I touch "OK" button on UIAlertview the cursor will be back from text field 3 to text field 2. Could you help me to solve problem touch OK Aleart view and back cursor from text field 3 to text field 2?
In the OK button handler of your AlertView write the following code
[textField2 becomeFirstResponder];
When you create Alertview give the delegate to self of that alert view.
YourAlertView.delegate = self;
Add delegate of Alertview to handle the button event of alert view.
If you have multiple Alertview then you should give them tag and differentiate according tags.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{
[textFiled2 becomeFirstresponder];
}
}

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;
}
}

objective c textField: selectAll text doesn't always work

I implemented this in the UITextField delegate:
-(void)textFieldDidBeginEditing:(UITextField *)iTextField {
[iTextField selectAll:iTextField];
}
My text field contain text.
When tapping on it, the keyboard goes up and all text selected.
when dismissing the keyboard and tapping again, no text selected (just blinking cursor).
when dismissing the keyboard and tapping again, all text selected again.
Any clue why does no text selected at the second tap?
have you tried with this?
textField.selectedTextRange = [textField textRangeFromPosition:textField.beginningOfDocument toPosition:textField.endOfDocument];
EDIT 1:
Now is going to work :), this call will be at the end of the queue
[textField performSelector:#selector(selectAll:) withObject:nil afterDelay:0.0];
I call selectAll in viewDidAppear works.

keep contents of textview till a button is pressed

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.

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.

Resources