加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

代理在swift?

发布时间:2020-12-14 06:15:56 所属栏目:百科 来源:网络整理
导读:如何做一个委托,即NSUserNotificationCenterDelegate在swift? 它与obj-c没有什么不同。 首先,必须在类声明中指定协议,如下所示: class MyClass: NSUserNotificationCenterDelegate 实现将如下所示: // NSUserNotificationCenterDelegate implementatio
如何做一个委托,即NSUserNotificationCenterDelegate在swift?
它与obj-c没有什么不同。
首先,必须在类声明中指定协议,如下所示:
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
}

当然,你必须设置委托。例如:

NSUserNotificationCenter.defaultUserNotificationCenter().delegate = self;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读