繁体   English   中英

如何使用代码模拟Swift iOS8中的按钮按下

[英]How can I simulate a button press in Swift iOS8 using code

如何使用Swift模拟View中的按钮按下。 我正在尝试获取日历权限并设置功能以在我单击当前运行的开始按钮时检查此授权

@IBAction func start(sender: AnyObject) {
//loads prompt to "Allow" or "Don't Allow" calendar permissions
eventStore.requestAccessToEntityType(EKEntityTypeEvent, completion: handler)

//checkAuth function looks at calendar authorization to get current status 
and then acts accordingly to dismiss View or load Privacy Settings
checkAuth()

}

我需要能够模拟按下“开始”按钮的按钮再次触发start()func。 到目前为止,我发现的唯一一件事似乎是在Objective-C中

[buttonObj sendActionsForControlEvents: UIControlEventTouchUpInside];

我不熟悉Obj-C,如果可能的话,需要一种在Swift中实现它的方法......谢谢

Swift翻译:

[buttonObj sendActionsForControlEvents: UIControlEventTouchUpInside];

是:

button.sendActions(for: .touchUpInside)

它实际上应该模拟按钮按下。

斯威夫特3

button.sendActions(for: UIControlEvents.touchUpInside)

斯威夫特4

button.sendActions(for: .touchUpInside)

尝试调用您的IBAction函数:

self.start(self)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM