我需要保留 NSAlert AlertDidEnd 的 contextInfo 吗?
我需要将带有几个选项的 NSDictionary 传递给
NSAlert - (void)beginSheetModalForWindow:(NSWindow *)window modalDelegate:(id)modalDelegate didEndSelector:(SEL)alertDidEndSelector contextInfo:(void *)contextInfo
文档没有说明是否必须保留 contextInfo
。现在,我在显示警报之前保留它并在 alertDidEnd:
中释放它,但最好确定是否有必要这样做。
I need to pass an NSDictionary
with a couple of options to
NSAlert - (void)beginSheetModalForWindow:(NSWindow *)window modalDelegate:(id)modalDelegate didEndSelector:(SEL)alertDidEndSelector contextInfo:(void *)contextInfo
The docs don't say anything about if the contextInfo
has to be retained or not. Right now I'm retaining it before showing the alert and releasing it in alertDidEnd:
, but it would be nice to know for sure if that is necessary.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
contextInfo
被认为是“原始”C 指针 (void *
) 并且可以是任何内容,因此管理内存是您的责任(如果您传递的是 Objective- C对象:保留它)。Since
contextInfo
is considered to be a "raw" C pointer (void *
) and can be anything, it's your responsibility to manage memory (if you're passing an Objective-C object: to retain it).