简体   繁体   中英

Pushing Viewcontroller through navigation controller , Showing Black screen

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)
}

在此输入图像描述

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let resultViewController = storyBoard.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
self.navigationController?.pushViewController(resultViewController, animated: true)

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.

let nextVC = self.storyboard?.instantiateViewControllerWithIdentifier("storyboardID") as! viewController
self.navigationController?.pushViewController(nextVC, animated: true)

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM