junaid
junaid

Reputation: 203

Getting warning "Presenting view controllers on detached view controllers is discouraged" while making window root view controller in app delegate?

Here is the code

let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyBoard.instantiateViewController(withIdentifier: "homeTBC") as! UITabBarController
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()

cant figure it yet.

Upvotes: 0

Views: 1671

Answers (2)

Mannopson
Mannopson

Reputation: 2684

From Apple's Documentation

When creating windows, always set the window’s initial size and specify the screen on which it is displayed.

Add the size:

self.window = UIWindow.init(frame: UIScreen.main.bounds)

Your complete code should be like that:

let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyBoard.instantiateViewController(withIdentifier: "homeTBC") as! UITabBarController
self.window = UIWindow.init(frame: UIScreen.main.bounds)
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()

Upvotes: 2

Saurabh pandey
Saurabh pandey

Reputation: 250

I have tried this code in My App for root view controller in app delegate working perfect:

As I think you are using this code in presented view controller or in presented navigation controller: Please send the scenario(Screen Shot) exact what you are doing?

    var window: UIWindow?
    window =  UIWindow(frame: UIScreen.main.bounds)
    window?.makeKeyAndVisible()
    let storyBoard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyBoard.instantiateViewController(withIdentifier: "TabbarVC") as! TabbarVC
    self.window?.rootViewController = vc

Upvotes: 2

Related Questions