我需要通知协议吗?

发布于 2024-07-20 21:50:53 字数 211 浏览 8 评论 0原文

我有使用 NSURLConnection 的 classDownload 。 我想将所有 NSURLConnection 事件保留在 classDownload 中。 ClassA想要使用classDownload同时还要接收connectionDidFinishLoading等通知,在classDownload中调用Finish。 如何获取从 classDownload 到 ClassA 的通知?

I have classDownload that uses NSURLConnection. I'd like to keep all of the NSURLConnection events in classDownload. ClassA wants to use classDownload but also receive notifications such as connectionDidFinishLoading, which is called Finish in classDownload. How do I get the notifications from classDownload over to ClassA?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萧瑟寒风 2024-07-27 21:50:53

假设classDownloadNSURLConnection的委托,您可以在调用委托方法时使用NSNotificationCenter来广播事件。 然后,在 classA 中,使用 addObserver: 订阅 classDownload 中的事件。 如果您需要任何说明或代码片段,请告诉我。

编辑

要直接回答标题中的问题,不,您不需要使用 NSNotificationCenter 订阅对象发布的事件的协议。

Assuming classDownload is the delegate of the NSURLConnection, you could just use NSNotificationCenter to broadcast events when the delegate methods are called. Then, in classA, subscribe to the events in classDownload using addObserver:. Let me know if you need any clarification or code snippets.

Edit

To directly answer the question in your title, no, you do not need a protocol to subscribe to events published by an object using NSNotificationCenter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文