[英]How can I simulate a button press in Swift iOS8 using code
How can I simulate a button press within a View in using Swift. 如何使用Swift模拟View中的按钮按下。 I'm trying to get Calendar permissions and have a function setup to check this authorization when I click the start button this currently runs 我正在尝试获取日历权限并设置功能以在我单击当前运行的开始按钮时检查此授权
@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()
}
I need to be able to simulate a button press of the Start button to trigger the start() func once again. 我需要能够模拟按下“开始”按钮的按钮再次触发start()func。 The only thing I've found so far seems to be in Objective-C 到目前为止,我发现的唯一一件事似乎是在Objective-C中
[buttonObj sendActionsForControlEvents: UIControlEventTouchUpInside];
I'm not familiar with Obj-C and need a way to implement this in Swift if possible...Thanks 我不熟悉Obj-C,如果可能的话,需要一种在Swift中实现它的方法......谢谢
The Swift translation of: Swift翻译:
[buttonObj sendActionsForControlEvents: UIControlEventTouchUpInside];
is: 是:
button.sendActions(for: .touchUpInside)
and it should in fact simulate a button push. 它实际上应该模拟按钮按下。
Swift 3 斯威夫特3
button.sendActions(for: UIControlEvents.touchUpInside)
Swift 4 斯威夫特4
button.sendActions(for: .touchUpInside)
尝试调用您的IBAction函数:
self.start(self)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.