迅速代表?

编程入门 行业动态 更新时间:2024-10-13 18:27:19
本文介绍了迅速代表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在 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;

更多推荐

迅速代表?

本文发布于:2023-11-26 20:37:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635108.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!