• <bdo id='HeVRM'></bdo><ul id='HeVRM'></ul>
    <legend id='HeVRM'><style id='HeVRM'><dir id='HeVRM'><q id='HeVRM'></q></dir></style></legend>
    <i id='HeVRM'><tr id='HeVRM'><dt id='HeVRM'><q id='HeVRM'><span id='HeVRM'><b id='HeVRM'><form id='HeVRM'><ins id='HeVRM'></ins><ul id='HeVRM'></ul><sub id='HeVRM'></sub></form><legend id='HeVRM'></legend><bdo id='HeVRM'><pre id='HeVRM'><center id='HeVRM'></center></pre></bdo></b><th id='HeVRM'></th></span></q></dt></tr></i><div id='HeVRM'><tfoot id='HeVRM'></tfoot><dl id='HeVRM'><fieldset id='HeVRM'></fieldset></dl></div>

      1. <tfoot id='HeVRM'></tfoot>

        <small id='HeVRM'></small><noframes id='HeVRM'>

        为什么设置 UIWindow 的 rootViewController 属性时 viewDidLoad 会被调用两次?

        时间:2023-10-03
      2. <tfoot id='x64Bm'></tfoot>
            <bdo id='x64Bm'></bdo><ul id='x64Bm'></ul>

                <legend id='x64Bm'><style id='x64Bm'><dir id='x64Bm'><q id='x64Bm'></q></dir></style></legend>

                <small id='x64Bm'></small><noframes id='x64Bm'>

                    <tbody id='x64Bm'></tbody>
                  <i id='x64Bm'><tr id='x64Bm'><dt id='x64Bm'><q id='x64Bm'><span id='x64Bm'><b id='x64Bm'><form id='x64Bm'><ins id='x64Bm'></ins><ul id='x64Bm'></ul><sub id='x64Bm'></sub></form><legend id='x64Bm'></legend><bdo id='x64Bm'><pre id='x64Bm'><center id='x64Bm'></center></pre></bdo></b><th id='x64Bm'></th></span></q></dt></tr></i><div id='x64Bm'><tfoot id='x64Bm'></tfoot><dl id='x64Bm'><fieldset id='x64Bm'></fieldset></dl></div>
                  本文介绍了为什么设置 UIWindow 的 rootViewController 属性时 viewDidLoad 会被调用两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  已经有几个类似的问题,但与我的情况并不完全相同.只需启动一个新的基于视图的项目,使用 NSLog 语句添加 viewDidLoadawakeFromNib 并在 MainWindow.xib 中进行以下更改:

                  There were already a couple of similar questions, but it wasn’t exactly the same as in my case. Just start a new view based project, add viewDidLoad and awakeFromNib with NSLog statements and do the following changes in MainWindow.xib:

                  • 删除应用程序委托中的视图控制器连接.
                  • UIWindow 的 rootViewController 委托连接到 App View Controller 实例.
                  • Remove the view controller connection in the application delegate.
                  • Connect UIWindow’s rootViewController delegate to the App View Controller instance.

                  第一次调用的堆栈跟踪:

                  The stack trace from the first call:

                  #0     0x000025c0 in -[foozaViewController viewDidLoad] at /Users/rafael/Downloads/fooza/fooza/foozaViewController.m:38
                  #1     0x000cd089 in -[UIViewController view] ()
                  #2     0x00040d42 in -[UIWindow addRootViewControllerViewIfPossible] ()
                  #3     0x0079d5e5 in -[NSObject(NSKeyValueCoding) setValue:forKey:] ()
                  #4     0x00050ff6 in -[UIView(CALayerDelegate) setValue:forKey:] ()
                  #5     0x0021930c in -[UIRuntimeOutletConnection connect] ()
                  #6     0x00d418cf in -[NSArray makeObjectsPerformSelector:] ()
                  #7     0x00217d23 in -[UINib instantiateWithOwner:options:] ()
                  #8     0x00219ab7 in -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] ()
                  #9     0x0001f17a in -[UIApplication _loadMainNibFile] ()
                  #10     0x0001fcf4 in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] ()
                  #11     0x0002a617 in -[UIApplication handleEvent:withNewEvent:] ()
                  #12     0x00022abf in -[UIApplication sendEvent:] ()
                  #13     0x00027f2e in _UIApplicationHandleEvent ()
                  #14     0x01004992 in PurpleEventCallback ()
                  #15     0x00dac944 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
                  #16     0x00d0ccf7 in __CFRunLoopDoSource1 ()
                  #17     0x00d09f83 in __CFRunLoopRun ()
                  #18     0x00d09840 in CFRunLoopRunSpecific ()
                  #19     0x00d09761 in CFRunLoopRunInMode ()
                  #20     0x0001f7d2 in -[UIApplication _run] ()
                  #21     0x0002bc93 in UIApplicationMain ()
                  #22     0x000020d9 in main ()
                  

                  这是第二次调用的痕迹:

                  And here’s the trace from the second call:

                  #0     0x000025c0 in -[foozaViewController viewDidLoad] at /Users/rafael/Downloads/fooza/fooza/foozaViewController.m:38
                  #1     0x00002555 in -[foozaViewController awakeFromNib] ()
                  #2     0x00217f26 in -[UINib instantiateWithOwner:options:] ()
                  #3     0x00219ab7 in -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] ()
                  #4     0x0001f17a in -[UIApplication _loadMainNibFile] ()
                  #5     0x0001fcf4 in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] ()
                  #6     0x0002a617 in -[UIApplication handleEvent:withNewEvent:] ()
                  #7     0x00022abf in -[UIApplication sendEvent:] ()
                  #8     0x00027f2e in _UIApplicationHandleEvent ()
                  #9     0x01004992 in PurpleEventCallback ()
                  #10     0x00dac944 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
                  #11     0x00d0ccf7 in __CFRunLoopDoSource1 ()
                  #12     0x00d09f83 in __CFRunLoopRun ()
                  #13     0x00d09840 in CFRunLoopRunSpecific ()
                  #14     0x00d09761 in CFRunLoopRunInMode ()
                  #15     0x0001f7d2 in -[UIApplication _run] ()
                  #16     0x0002bc93 in UIApplicationMain ()
                  #17     0x000020d9 in main ()
                  

                  这是期望的行为还是错误?我们还应该使用更传统的将插座连接到根视图控制器的方法应用程序委托保持一个理智的 viewDidLoad/viewDidUnload 比率还是我们应该忽略苹果的规则,不要在 awakeFromNib 中调用 super 并使用 UIWindow 的新 rootViewController 属性?

                  Is this desired behavior or a bug? Should we still use the more traditional way of connecting an outlet to the root view controller in the application delegate to maintain a sane viewDidLoad/viewDidUnload ratio or should we ignore Apple’s rules and do not call super in awakeFromNib and use the new rootViewController property of UIWindow?

                  推荐答案

                  它看起来像一个错误,因为它只能在 Xcode 4 中重现.我将提交一个错误.

                  It looks like a bug, because it’s only reproducible in Xcode 4. I will file a bug.

                  另请参阅 http://shurl.at/5u(Apple 开发者论坛)

                  See also http://shurl.at/5u (Apple Developer Forums)

                  这篇关于为什么设置 UIWindow 的 rootViewController 属性时 viewDidLoad 会被调用两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:点击 MFMailComposeViewController 的取消按钮时,操作表不显示 下一篇:iOS 4 有一个用于发送消息的 In-App SMS SDK,但有没有办法让您的应用程序接收传入的 SMS 消息?

                  相关文章

                  1. <i id='DkAGj'><tr id='DkAGj'><dt id='DkAGj'><q id='DkAGj'><span id='DkAGj'><b id='DkAGj'><form id='DkAGj'><ins id='DkAGj'></ins><ul id='DkAGj'></ul><sub id='DkAGj'></sub></form><legend id='DkAGj'></legend><bdo id='DkAGj'><pre id='DkAGj'><center id='DkAGj'></center></pre></bdo></b><th id='DkAGj'></th></span></q></dt></tr></i><div id='DkAGj'><tfoot id='DkAGj'></tfoot><dl id='DkAGj'><fieldset id='DkAGj'></fieldset></dl></div>

                    • <bdo id='DkAGj'></bdo><ul id='DkAGj'></ul>

                    <legend id='DkAGj'><style id='DkAGj'><dir id='DkAGj'><q id='DkAGj'></q></dir></style></legend>

                    <tfoot id='DkAGj'></tfoot>

                    <small id='DkAGj'></small><noframes id='DkAGj'>