How can I simulate a button press within a View in using Swift. 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. The only thing I've found so far seems to be in Objective-C
[buttonObj sendActionsForControlEvents: UIControlEventTouchUpInside];
I'm not familiar with Obj-C and need a way to implement this in Swift if possible...Thanks
The Swift translation of:
[buttonObj sendActionsForControlEvents: UIControlEventTouchUpInside];
is:
button.sendActions(for: .touchUpInside)
and it should in fact simulate a button push.
Swift 3
button.sendActions(for: UIControlEvents.touchUpInside)
Swift 4
button.sendActions(for: .touchUpInside)
尝试调用您的IBAction函数:
self.start(self)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.