Start function on timeout in iPhone - iphone

I need to change the value of title of button just for 2 seconds and after i should return the title back.
I'm changing the title in code below:
[self.loginField.titleLabel setText:#"New Text"];
So how can i change back the title to "Old Text" in 2 seconds? Is there a "timeout" function with callback?

Try:
[self.loginField.titleLabel performSelector:#selector(setText:) withObject:#"Old Text" afterDelay:2.0];

Related

How to wait till progressbar disapper?

I want enter window and wait till element is present. Problem is, when i enter this window, this element is present and clickable, but after short time progressbar apper, and window is blocked till this progressbar works. How to wait properly for elements ?
I tried below code, doesn't work, but it show what i want obtain (click addButton, wait for progressbar or 5sec passed, and then wait for element id displayed.
this.openWindow = function(addButton, progressbar, targetElement){
addButton.click().then(function(){
browser.driver.wait(progressbar.isDisplayed(), 5000).then(function(){
browser.driver.wait(targetElement.isDisplayed(), 5000);
});
});
};
Checkout official documentation for stalenessOf:
You should do something like this
this.openWindow = function(addButton, progressbar) {
var EC = protractor.ExpectedConditions;
return addButton.click().then(function(){
return browser.driver.wait(EC.stalenessOf(progressbar), 5000, 'Progress bar was not hidden within 5 sec');
});
};
And then you can use your function like this
openWindow(addButton, progressbar).then(...)
The code above will be resolved when progress bar has been hidden or will fail if time is out.
If progress bar is not completely removed from DOM, you can also try invisibilityOf

Swift UIAlertController fire once per row select textfield edited

I have a UIPickerView with an if statement in selectedRowInComponent that checks the value of a textField. If the user inputed number in the textfield is greater than 10, an alert is called. All is working well except I'd like to have the alert only fire a single time after the row is selected and the field is edited. As it stands, the alert is called every time the field is updated/edited with a value greater than 10. The initial alert is sufficient. Any tips on how I can accomplish this? Thanks!
if (inputField.text! as NSString).doubleValue > 10 {
SweetAlert().showAlert("Number is greater than 10", subTitle: "Please select number less than 10", style: AlertStyle.CustomImag(imageFile: "alertimage.png"))
}
Quick and Dirty:
Create a bool variable publicly available in your viewController and initialize it with false (lets call the variable 'alertAlreadyShown')
Then just make an if statement about that bool in your pickerView method
if (inputField.text! as NSString).doubleValue > 10 {
if (alertAlreadyShown == false) {
SweetAlert().showAlert(...)
alertAlreadyShown = true
}
}
But don't forget to reset the bool at appropriate times to enable the alert again
There's two ways you could go about this. One would be (and the most user friendly in my opinion) only show values of less than ten in your picker view. The other option would be to set a bool for whether or not the alert had been displayed, and add that as a check to your if statement.

How can I touch a UIAlertView's 'OK' or 'Cancel' button using Frank?

I have tried a few different things including this:
When /^I touch the alertview button marked "(.*?)"$/ do |alert_btn_name|
touch "view: 'UIAlertButton' marked:'#{alert_btn_name}'"
end
and
When /^I touch the (\d*)(?:st|nd|rd|th)? alert view button$/ do |ordinal|
ordinal = ordinal.to_i
touch( "alertView threePartButton tag:#{ordinal}" )
end
What is a good way to go about doing this?
Your code looks good, is it not working?
You can also try to use the Frank predefined steps, and just do:
When I touch "Cancel"
Then I should not see an alert view
Or if you want the actual step for "When I touch ..", it would be:
When /^I touch "([^\"]*)"$/ do |mark|
quote = get_selector_quote(mark)
selector = "view marked:#{quote}#{mark}#{quote} first"
if element_exists(selector)
touch( selector )
else
raise "Could not touch [#{mark}], it does not exist."
end
sleep 1
end

Xcode update label text from other class

Few days back this question was about changing the label text from an other class. I changed a few things around:
I now have a function setLabelText:
- (void)setLabelText:(NSString*)text{
//myLabel.text = text;
[myLabel performSelectorOnMainThread : # selector(setText : ) withObject:text waitUntilDone:YES];
NSLog(#"class:%#, label:%#", self, myLabel);
}
Both self and label are filled, but the display is not showing the correct text..
I'm calling this function from an other class, if I change my label text from a button on the viewcontroller it changes correctly.
EDIT:
I have the label changing now, every time when the class is done with it's functions the label edits the text. Although.. this is always the last set value, I need it to change every time it gets into a for loop, how can I get this to work? Seems it doesn't update the viewController while the app is doing it's for loop

Strange issues with tag label 0?

I have created a bar over the keyboard for textfields with previous/next/done button selections. In doing so, I noticed an odd occurance with my tags that I used to navigate between the textfields. I am creating my interface programmatically with a loop, and as such, just set the tag values to the loop variable i.
I started the i variable at 0 so the very first text field created had a tag of zero. Basically what was happening is the 'previous' button functionality would only go so low as 1. It wouldn't even go back to the text field with the 0 tag. The only way to fix this was to increase all tag values by 1 so the first text field started at 1 instead of zero.
Here is my code. Is there a bug in my code that I cannot see? or is this a weird issue with tags?
-(void)gotoPrevTextfield{
// If the active textfield is the first one, can't go to any previous
// field so just return.
UITextField *textField = (UITextField *)[inputsView viewWithTag:0];
NSLog(#"%i",textField.tag);
NSLog(#"%i",txtActiveField.tag);
if (txtActiveField == textField) {
NSLog(#"returning at previous");
return;
}
else {
NSLog(#"set responder");
// Otherwise if a different textfield has the focus, the operation
// of "previous" button can be done and set the previous as the first
// responder.
textField = (UITextField *)[inputsView viewWithTag:txtActiveField.tag - 1];
NSLog(#"%i",textField.tag);
NSLog(#"%i",txtActiveField.tag);
[textField becomeFirstResponder];
}
}
Note that unset tags default to 0 so that is almost a poor choice. You may be getting another view that you don't expect.
A fairly good practice is to add some constant such as 100, consider making the constant a const int or #define for clarity.