Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

enter image description here

like image 957
Joe Avatar asked Aug 23 '16 12:08

Joe


People also ask

How do I know if Viewcontroller is visible?

The view's window property is non-nil if a view is currently visible, so check the main view in the view controller: Invoking the view method causes the view to load (if it is not loaded) which is unnecessary and may be undesirable. It would be better to check first to see if it is already loaded.

How do I embed a view controller in navigation controller storyboard?

In your storyboard, select the initial view controller in your hierarchy. With this view controller selected, choose the menu item Editor -> Embed In -> Navigation Controller .


2 Answers

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let resultViewController = storyBoard.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
self.navigationController?.pushViewController(resultViewController, animated: true)
like image 58
Chirag Patel Avatar answered Sep 20 '22 17:09

Chirag Patel


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.

like image 30
Christopher Rex Avatar answered Sep 17 '22 17:09

Christopher Rex