NSNotification当天变化? [英] NSNotification when the day changes?

查看:122
本文介绍了NSNotification当天变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WebKit的WebHistory API按日期隔离其项目。所以当天变化时,我需要重新分配任何昨天和/或(早期)今天(或明天!)标签。这是否有NSNotification?或者我必须依靠NSTimer或 -performSelector:withObject:andDelay:或其他一些技术吗?

The WebKit's WebHistory API segregates its items by date. So when the day changes, I need to reassign any "Yesterday" and/or "(Earlier) Today" (or "Tomorrow"!) labels. Is there a NSNotification for this? Or do I have to rely on NSTimer or -performSelector:withObject:andDelay: or some other technique?

当然,替代方法不会自动处理回溯。)

(Of course, the alternate methods don't automatically handle back-dating.)

附录

在写这篇文章时,有两个答案,但有一个后来被删除的第三个答案。它有最全面的反应。它提到WWDC-2013会议227,讨论小牛日期/时间系统中未记录的添加。有改进的检查今天和通知一天的变化。您可以查看 OS X v10.9的Foundation Release Notes的三分之二

As of this writing there are two answers, but there was a third that was later removed. It had the most comprehensive response. It referred to WWDC-2013 Session 227, which discusses undocumented additions to the Date/Time system in Mavericks. There is improved checking for Today and a notification for a day change. You can check out two-thirds down the Foundation Release Notes for OS X v10.9.

如果被删除的答案的所有者想把东西放回来,我会转移答案标志,如果可能的话。)我有我的Mac在2013年年底,立即升级到Mavericks,所以我不在乎前小牛系统和

(If the deleted-answer's owner wants to put something back, I'll transfer the answer flag, if possible.) I got my Mac in late 2013 and immediately upgraded it to Mavericks, so I don't care about pre-Mavericks systems and Mavericks-only APIs are OK.

推荐答案


这是否有NSNotification?

Is there a NSNotification for this?

否,Mac OS在日期变化时不发送通知。

No, Mac OS does not send notifications when the day changes.


当天变化时,我需要重新分配任何昨天[...]标签

when the day changes, I need to reassign any "Yesterday" [...] labels

显示标签的UI类型。在临时的用户界面,如菜单,最好只是在显示UI时计算标签,并保留原样。

This depends on the type of UI showing the label. In temporarily UIs, like menus, it's probably better to just calculate the label when revealing the UI and leave it as it is.

如果任何UI显示标签较长时间,像侧边栏,最好是每天更改时真正更新。

If any UI displays the label for a longer time, like a sidebar, it's best to really update when the day changes.

要做到这一点,你应该计算下一次更改的时间,并设置一个计时器。此外,您可能需要注册一些通知以检测非标准日更改(系统睡眠,调整系统时间,日历更改)。

To do this, you should then calculate the time of the next change and set up a timer. Additionally, you might want to register for some notifications to detect non-standard day changes (system sleep, adjusting the system time, calendar changes).

这里的代码,做所有这一切,只是发送通知。它可以在iOS和Mac OS上运行。

Here's code that does all of this and simply sends a notification. It work's on both iOS and Mac OS.

这篇关于NSNotification当天变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆