Issue Description: In iOS 18, when setting the root view controller of a UINavigationController and immediately pushing another view controller, the root view controller's lifecycle methods, such as viewDidLoad(), are not called as expected. This issue does not occur in previous iOS versions. There is no mention of this behavior in the iOS 18 release notes, and it is causing significant issues in our application.
Steps to Reproduce: Set the root view controller of a UINavigationController. Immediately push another view controller. Observe that the root view controller's lifecycle methods, such as viewDidLoad(), are not called. Example Code: Swift import UIKit
class HomeViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() print("HomeViewController viewDidLoad") } }
class SecondViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() print("SecondViewController viewDidLoad") } }
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
let home = HomeViewController()
let rootNav = UINavigationController(rootViewController: home)
window?.rootViewController = rootNav
window?.makeKeyAndVisible()
let secondViewController = SecondViewController()
home.navigationController?.pushViewController(secondViewController, animated: true)
return true
}
} Expected Behavior: The root view controller's lifecycle methods, such as viewDidLoad(), should be called when setting it as the root view controller of a UINavigationController.
Actual Behavior: In iOS 18, the root view controller's lifecycle methods are not called when it is set as the root view controller and another view controller is immediately pushed.
Impact: This issue affects the proper initialization and setup of the root view controller, causing significant disruptions in our application's workflow.
Device Information: iOS Version: iOS 18 Test Devices: iPhone 15, iPhone 16 Additional Information: We would appreciate any insights or updates on whether this is an intended optimization or a potential bug. This issue is causing significant disruption to our application, and a timely resolution would be greatly appreciated.