简体   繁体   English

NSApplication委托调用的顺序

[英]Order of NSApplication delegate calls

I'm noticing something strange in my NSApplication delegate callbacks. 我在NSApplication委托回调中注意到一些奇怪的事情。 When I start the app with debugger attached, I see what I expect: applicationDidFinishLaunching: is called first, then applicationDidBecomeActive: 当我开始调试应用程序连接,我看到预期的结果: applicationDidFinishLaunching:首先调用,然后applicationDidBecomeActive:

When I run the app without the debugger, I get the calls in the order reversed: applicationDidBecomeActive: is called before applicationDidFinishLaunching: 在没有调试器的情况下运行应用程序时,我得到的调用顺序相反: applicationDidBecomeActive:之前调用applicationDidFinishLaunching:

Is there a reason for this? 是否有一个原因? It makes it very confusing to account for different scenarios based on debugger vs. non-debugger. 考虑到基于调试器还是非调试器的不同情况,这非常令人困惑。

[note: testing this is in Mavericks] [注意:在Mavericks中进行测试]

The relative order of those delegate methods during launch is not documented, so you should not rely on any particular order. 这些委托方法在启动过程中的相对顺序没有记录,因此您不应依赖任何特定顺序。

If you're concerned about some initialization not having been done when -applicationDidBecomeActive: is called, then you should do that initialization in -applicationWillFinishLaunching: rather than in -applicationDidFinishLaunching: . 如果您担心在调用-applicationDidBecomeActive:时尚未完成某些初始化,则应在-applicationWillFinishLaunching:而不是在-applicationDidFinishLaunching:中进行初始化。 Alternatively, you should do the initialization on demand, such as initializing a property when its value is first requested. 另外,您应该按需进行初始化,例如在首次请求属性值时初始化属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 捆绑包中NSApplication委托的使用 - Use of NSApplication delegate in bundle 在PyObjC中为openFile实现NSApplication委托协议 - Implementing NSApplication delegate protocol for openFile in PyObjC Objective-C 10.10 NSApplication委托无法调用委托类中定义的方法 - Objective-C 10.10 NSApplication delegate cannot call method defined in delegate class GCDAsyncSocket委托调用不起作用 - GCDAsyncSocket Delegate Calls Not Working 为什么我必须继承NSobject而不是NSapplication来在GNUSTEP上实现委托方法? - why must i inherit NSobject instead of NSapplication to implement delegate method on GNUSTEP? UITableview委托方法的执行顺序 - Order of execution of the UITableview delegate method UITableView永远不会在其委托上调用tableView:shouldShowMenuForRowAtIndexPath: - UITableView never calls tableView:shouldShowMenuForRowAtIndexPath: on its delegate 区分对相同委托方法的调用 - Differentiate between calls to the same delegate method 为什么UITableView调用UIScrollView的委托方法? - Why UITableView calls UIScrollView's delegate methods? NSFetchedResultsController(和UITableView)委托方法调用增长和增长 - NSFetchedResultsController (and UITableView) delegate methods calls growing and growing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM