我正在尝试更新已发送通知(提醒)的副标题中的字符串,我正在使用NSTimer
这样做:
[NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(updateSubtitle)
userInfo:nil
repeats:YES];
- (void)updateSubtitle
{
[[NSUserNotificationCenter defaultUserNotificationCenter].deliveredNotifications
enumerateObjectsUsingBlock:^(NSUserNotification *notification, NSUInteger idx, BOOL *stop) {
notification.subtitle = @"new subtitle";
}];
}
代码每5秒正确执行一次。但是通知警报中显示的副标题不会改变。
有没有办法强制像setNeedsDisplay
或类似的东西“重绘”?
感谢。
答案 0 :(得分:2)
我知道这篇文章有些陈旧,但我最近试图弄清楚同样的事情,但最终需要删除现有的通知并添加一个具有相同标题的新通知。
我在创建通知的标识符字段时使用NSUUID,然后使用类似(在Swift中)的内容找到现有的NSUUID:
var notif = NSUserNotification()
notif.identifier = <Id To Search For>
NSUserNotificationCenter.defaultUserNotificationCenter().removeScheduledNotification(notif)
NSUserNotificationCenter.defaultUserNotificationCenter().removeDeliveredNotification(notif)