【问题标题】:Custom NSUserNotifictation object自定义 NSUserNotification 对象
【发布时间】:2016-12-21 14:12:12
【问题描述】:

我正在尝试修改 NSUserNotifictation 以传递自定义变量:

@interface MyUserNotification: NSUserNotification
@property (nonatomic) int theid;
@property (nonatomic) NSString* url;
@end

@implementation MyUserNotification
@end

然后在我的AppDelegate 对象中启动时:

MyUserNotification *notification = [[MyUserNotification alloc] init];
notification.theid = theid;

设置theid 会抛出错误:

-[_NSConcreteUserNotification setTheid:]: unrecognized selector sent to instance 0x100204840

NSConcreteUserNotification 对象为何参与其中?

【问题讨论】:

    标签: objective-c macos cocoa nsusernotification


    【解决方案1】:

    所以这个类似乎并不意味着被覆盖,但好消息:有一个userInfo dict?

    因此,您可以将任何对象作为 KV 对存储在 userInfo 字典中...

    int theid;
    NSUserNotification *notification = [[NSUserNotification alloc] init];
    NSDictionary * userInfo = [NSMutableDictionary dictionary];
    [userInfo setValue:@(theid) forKey:@"theid"];
    notification.userInfo = userInfo;
    

    【讨论】:

    猜你喜欢
    • 2013-11-16
    • 1970-01-01
    • 2012-09-23
    • 1970-01-01
    • 2016-03-31
    • 2016-10-08
    • 2011-04-14
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多