多种方法 NSNotificationCenter iPhone
我有很多方法需要前一个方法完成才能触发下一个方法。我想我应该 NSNotificationCenter 而不是 PerformSelector afterDelay 并且只是希望该方法到那时完成。
有人可以规划出如何以及在何处将通知添加到 Method1、Method2 和 Method3,其中 1 需要在 2 之前完成(而不仅仅是触发),在 3 之前完成。
谢谢
I have many methods that need the previous one to complete before firing the next one. I'm thinking I should NSNotificationCenter rather than performSelector afterDelay and just hope the method is done by that time.
Can someone map out how and where to add the notification to Method1, Method2 and Method3 where 1 needs to complete (not just fire) before 2 before 3.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,不要将通知用作方法调用。它们应该用来表明某件事已经发生或将要发生。
来自 Apple 的“Cocoa 编码指南”:
通知由全局 NSString 对象标识,其名称的组成方式如下:
[关联类的名称] + [Did | Will] + [UniquePartOfName] + 通知
例如:
In general do not use notifications as method calls. They should be used to indicate that something did or will occur.
From Apple's "Coding Guidelines for Cocoa":
Notifications are identified by global NSString objects whose names are composed in this way:
[Name of associated class] + [Did | Will] + [UniquePartOfName] + Notification
For example: