【问题标题】:Do I need to retain the contextInfo for NSAlert alertDidEnd?我需要为 NSAlert alertDidEnd 保留 contextInfo 吗?
【发布时间】:2011-12-14 20:12:55
【问题描述】:

我需要传递一个NSDictionary 和几个选项来

NSAlert - (void)beginSheetModalForWindow:(NSWindow *)window modalDelegate:(id)modalDelegate didEndSelector:(SEL)alertDidEndSelector contextInfo:(void *)contextInfo

文档没有说明是否必须保留 contextInfo。现在我在显示警报之前保留它并在alertDidEnd: 中发布它,但很高兴知道这是否有必要。

【问题讨论】:

    标签: cocoa memory-management nsalert


    【解决方案1】:

    由于contextInfo 被认为是“原始” C 指针 (void *) 并且可以是任何东西,因此您有责任管理内存(如果您传递的是 Objective-C 对象:保留它)。

    【讨论】:

    • 感谢您的快速回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-07
    • 2013-09-14
    • 2011-03-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-06
    相关资源
    最近更新 更多