Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why viewDidLayoutSubviews is called twice only on first run?

It's driving me crazy this. Only on first run the viewDidLayoutSubviews is called twice.

Here is the code I'm using:

class CICViewController: UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()
    }



    func addQLabel(qLabel: UILabel, questionString: String, bgrLabel: UILabel) {// some code goes here
    }

    func makeRoundQButtons(qButtons:[UIButton]) {
      // some code goes here

    }

    func addArrows(numberOfArrows:Int, buttonCurAngle:Double) {//some code goes here
    }

    func animateButtons(qButtons:[UIButton], buttonCurAngle:Double) {

     // some code goes here

    }



    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

    }

    func backTapped(sender: UIBarButtonItem) {
        navigationController?.popViewControllerAnimated(false)
       //some code goes here

    }

    func restartTapped(sender: UIBarButtonItem) {
        navigationController?.popToRootViewControllerAnimated(false)
        //some code goes here
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

} 

And in my ViewController I call this :

class OneViewController: CICViewController {

  override func viewDidLoad() {
        super.viewDidLoad()

 //some code goes here
}


    override func viewDidLayoutSubviews() {

        super.viewDidLayoutSubviews()
        print("viewDidLayoutSubviews")
        self.makeRoundQButtons(qButtons)
        self.animateButtons(qButtons, buttonCurAngle: 2.0)

    }

    override func viewDidAppear(animated: Bool) {
     //nothing goes here
    }


}
like image 214
George Asda Avatar asked May 14 '16 13:05

George Asda


1 Answers

There is no guarantee as for how many times viewDidLayoutSubviews will be called.

You can find a great discussion in this Stack Overflow post:
When is layoutSubviews called?

like image 173
maddy Avatar answered Sep 19 '22 23:09

maddy