本文介绍了迅速代表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 swift 中创建一个委托,即 NSUserNotificationCenterDelegate?
How does one go about making a delegate, i.e. NSUserNotificationCenterDelegate in swift?
推荐答案它与 obj-c 并没有什么不同.首先,您必须在类声明中指定协议,如下所示:
It is not that different from obj-c. First, you have to specify the protocol in your class declaration, like following:
class MyClass: NSUserNotificationCenterDelegate实现将如下所示:
// NSUserNotificationCenterDelegate implementation func userNotificationCenter(center: NSUserNotificationCenter, didDeliverNotification notification: NSUserNotification) { //implementation } func userNotificationCenter(center: NSUserNotificationCenter, didActivateNotification notification: NSUserNotification) { //implementation } func userNotificationCenter(center: NSUserNotificationCenter, shouldPresentNotification notification: NSUserNotification) -> Bool { //implementation return true }当然,你必须设置委托.例如:
Of course, you have to set the delegate. For example:
NSUserNotificationCenter.defaultUserNotificationCenter().delegate = self;更多推荐
迅速代表?
发布评论