9

I being searching this issue in stack overflow but couldn't get an exact answer to the issue, i being stuck in it for long time. Mine issue is i'm trying to push a TestViewController through navigation controller. when i click the button the TestViewController is being load with navigation bar and the UIScreen is in black colour.

Code of TestViewController

import UIKit
class TestViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }   

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(true)
        navigationItem.title = "Test page"
    }
}

Code of Button

@IBAction func secondButtonClicked(sender: AnyObject) {
    buttonPressedNumber = "Two Clicked"
    buttonTextColor = UIColor.magentaColor()
      let a = TestViewController()
      let b:UIViewController = a as UIViewController
      navigationController?.pushViewController(b, animated: false)
}

enter image description here

Nirav D
  • 71,513
  • 12
  • 161
  • 183
Joe
  • 859
  • 2
  • 10
  • 27

4 Answers4

17
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let resultViewController = storyBoard.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
self.navigationController?.pushViewController(resultViewController, animated: true)
Chirag Patel
  • 1,453
  • 1
  • 11
  • 21
8

You have not set the background color of your view.

The default color of the of UIWindow is Black. So if you have not set any other background colors in the stack they will all be transparent.

Not setting an appropriate background color for your UIViewController's view will also cause weird visuals during a transition.

Christopher Rex
  • 392
  • 3
  • 10
6
let nextVC = self.storyboard?.instantiateViewControllerWithIdentifier("storyboardID") as! viewController
self.navigationController?.pushViewController(nextVC, animated: true)
Keyur Hirani
  • 1,607
  • 14
  • 22
0

not sure the background colour is set to white these days. therefore, if view controller is created programmatically

in viewDidLoad/viewWillAppear for a white background colour

view.backgroundColor = UIColor.whiteColor()