swift - 如何以编程方式单击按钮?

标签 swift uibutton

我有 2 个 View Controller ,应该根据用户输入进行交换。因此,我想根据从文本文件中获得的输入以编程方式切换 View 。

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

有关如何以编程方式单击按钮或使用输入加载特定 View Controller 的任何帮助?

最佳答案

要以编程方式触发事件,您需要调用 sendActionsForControlEvent

button.sendActionsForControlEvents(.TouchUpInside)

--

swift 3

button.sendActions(for: .touchUpInside)

关于swift - 如何以编程方式单击按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39336562/

相关文章:

ios - 打破动画 block 内的循环

ios - 获取 UIButton 的大小并右对齐

swift - 以编程方式设置 UIButton 内标签的框架大小

swift - 是否可以向 Swift 协议(protocol)一致性扩展添加类型约束?

ios - Objective C 中类似 Swift 的结构

ios - 无法在 collectionView Cell 的所有边上应用阴影

ios - Swift ios 中的自定义谷歌地图标记图标图像

ios - 如何在 iOS 中绘制纹理按钮?

iOS - UIButton 图像不符合预期

ios - 在单独的类中调用 UIButton