Coding4Life Coding4Life - 3 months ago 14
Swift Question

Swift : How to click a button programmatically?

I have 2 view controllers which should be swapped according to userinput. So,I want to switch the views programatically based on the input I get from a text file.

Algorithm :
if(input == 1)
{
Go to View Controller 1
}
else if(input ==2)
{
Go to View Controller 2
}


any help on how to click the button programmatically or load that particular viewcontroller with input!.

Answer

To fire an event programmatically you need to call sendActionsForControlEvent

button.sendActionsForControlEvents(.TouchUpInside)