[英]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.