【转载】User notification 的实现方法
原帖请看:http://cocoathings.blogspot.com/2013/01/introduction-to-user-notifications-in.html
想要实现如图这样的notification popup


弹出notification的代码如下
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = @"Hello, World!";
notification.informativeText = [NSString stringWithFormat:@"details details details"];
notification.soundName = NSUserNotificationDefaultSoundName;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
但是这个popup并不是默认显示的,想要让他show出来还必须在程序里实现下面的方法:
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
shouldPresentNotification:(NSUserNotification *)notification
{
return YES;
}
然后把NSUserNotificationCenter.的delegate设置为自己的程序,一般在主程序AppDelegate.m中实现即可(上面那个函数也在这个文件里)
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
}
需要注意的是,想要成功设置delegate还必须让AppDelegate支持NSUserNotificationCenterDelegate 协议,即在它的头文件里加上这个协议即可。
然后运行程序就OK了。
【转载】User notification 的实现方法的更多相关文章
- 【转载】C#使用Trim方法去除字符串前后的所有空格
在C#语言程序开发过程中,很多时候需要对字符串对象的前后空格进行去除,此时就需要使用到Trim()方法来实现这个功能,Trim()方法可以快速去除字符串前端和后端的所有空格. 例如有个字符:strin ...
- 【转载】C#通过IndexOf方法判断某个字符串是否包含在另一个字符串中
C#开发过程中针对字符串String类型的操作是常见操作,有时候需要判断某个字符串是否包含在另一个字符串,此时可以使用IndexOf方法以及Contain方法来实现此功能,Contain方法返回Tru ...
- 【转载】C#使用FirstOrDefault方法快速查找List集合中符合条件的第一个实体
在C#的List集合的操作中,有时候我们需要根据相关条件快速从List集合中获取到第一个符合条件的实体对象,例如有个全校班级的List集合,我们需要根据班级代码快速从List集合中查找出班级信息.可以 ...
- ListView:The content of the adapter has changed but ListView did not receive a notification终极解决方法
使用ListView时遇到如下的异常信息: 10-26 18:30:45.085: E/AndroidRuntime(7323): java.lang.IllegalStateException: T ...
- Android The content of the adapter has changed but ListView did not receive a notification终极解决方法
这几天做一个自动扫描SD卡上所有APK文件的小工具,扫描过程中会把APK添加到LISTVIEW中显示,结果出现以下错误:(有时候触摸更新数据时候,触摸listview也会报错) E/AndroidRu ...
- 转载:Java多线程中join方法的理解
转载自:http://uule.iteye.com/blog/1101994 thread.Join把指定的线程加入到当前线程,可以将两个交替执行的线程合并为顺序执行的线程.比如在线程B中调用了线程A ...
- 转载:[Java]读取文件方法大全
转载网址:http://www.cnblogs.com/lovebread/archive/2009/11/23/1609122.html 1.按字节读取文件内容 2.按字符读取文件内容 3.按行读取 ...
- 【转载】ArrayList使用LastIndexOf方法查找最后一个符合条件的元素位置
在C#的编程开发中,ArrayList集合是一个常用的非泛型类集合,在ArrayList集合中如果需要查找最后一个符合条件的元素所在的位置,可以使用ArrayList集合的LastIndexOf方法, ...
- 【转载】C#使用InsertRange方法往ArrayList集合指定位置插入另一个集合
在C#的编程开发中,ArrayList集合是一个常用的非泛型类集合,ArrayList集合可存储多种数据类型的对象.在实际的开发过程中,我们可以使用InsertRange方法在ArrayList集合指 ...
随机推荐
- Fragment切换页面
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- 用pypy运行ryu
最近看到pypy可以提高python的运行速率到很变态的境地,加之现在ryu发现拓扑的能力有限,不能满足实验要求,所以想将其试着在pypy上运行 部署pypy在virtualenv,在学python初 ...
- Codeforces 678E(Another Sith Tournament)
题目链接:传送门 题目大意:有n个人决斗(n<=18),每两个人之间都有一定几率杀死对方,一次进行一次决斗,胜利者成为擂主继续接受决斗直到只剩下一个人,你是一号,问你最大有多大几率存活到最后. ...
- JZOJ.5264【NOIP2017模拟8.12】化学
Description
- python中的str()与eval函数
author:headsen chen date:2018-04-09 10:48:22 eval函数是把str转化成list.dict.tuple str函数把list,dict,tuple ...
- npm and node 的一些问题
1. node 安装 n 模块 用来管理 node的版本 2. 初始化项目出现这个问题 Error: Attempt to unlock XXX, which hasn't been locked ...
- [LintCode] O(1)检测2的幂次
class Solution { public: /* * @param n: An integer * @return: True or false */ bool checkPowerOf2(in ...
- PHP使用SimpleElement创建和解析xml文件
<!-- 使用SimpleXMLElement生成xml文件 --><?php//生成一个xml文件 //xml字符串$_xml = <<<_xml<?xml ...
- Office word中去掉首页的页眉
1.首先将光标位置移动到第二页的开始,然后点击页面布局命令. 2.页面布局里面找到分隔符,找到下一页的分隔符.(分页符分页) 3.双击第二页的页眉,打开页眉编辑菜单.将连接到前一条页眉的命令去掉. 4 ...
- MVC4 WebAPI中如何返回一张图片
public HttpResponseMessage Get(string imageName, int width, int height) { Image img = GetImage(image ...