gpt4 book ai didi

objective-c - 如何在 Objective-C 中创建一个 NSNotification 对象?

转载 作者:太空狗 更新时间:2023-10-30 03:49:49 37 4
gpt4 key购买 nike

我想创建一个 NSNotification 对象:

NSNotification *obj=[[NSNotification alloc]init];

但是当我这样创建时,我得到一个异常,因为“NSConcreteNotification init: is not allowed”。我该如何解决这个问题?

最佳答案

来自NSNotification文档:

You can create a notification object with the class methods notificationWithName:object: or notificationWithName:object:userInfo:. However, you don’t usually create your own notifications directly. The NSNotificationCenter methods postNotificationName:object: and postNotificationName:object:userInfo: allow you to conveniently post a notification without creating it first.

关于objective-c - 如何在 Objective-C 中创建一个 NSNotification 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2309619/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com