Global property not passed to UIView subclass via setNeedsDisplay() does not

Hello.


I have a UIViewController with a subclassed UIView in it (that draws a graph). The strange problem is that in the viewWillAppear method of the UIViewController, one of my global variables that determines how the image will be drawn in the UIView is passed correctly, whereas in the UIView subclass, it is not.


Let me explain.


My UIViewController:

My ViewController:

override func viewWillAppear(animated: Bool)
    {
        print("WILLAPPEAR AND WHAT IS DATA HERE? ",appSingleton.isWindAloftUSShared )
        self.viewWindFrame.setNeedsDisplay()
     }


My UIView subclass:


class IGAWindAloftDrawView: UIView
{

    override func drawRect(rect: CGRect)
     {
        print("THIS IS PASSED",appSingleton.isWindAloftUSShared)
  
        if appSingleton.isWindAloftUSShared == true
          {
               draw1()
          }
        else if appSingleton.isWindAloftUSShared == false
         {
               draw2()
         }
     }
}


The global property is always true in the UIView subclass for some reason:


WILLAPPEAR AND WHAT IS DATA HERE? false

THIS IS PASSED true


I have checked the classes and I do not seem to be assigning the value back to true anywhere in the subclass or the UIViewController.


Thanks a lot in advance if someone has an idea what may be happening!

Accepted Reply

1) You should call super.viewWillAppear. Probably not related.


2) Is "appSingleton" correctly defined and instantiated? Obviously you intend it to be a singleton, but perhaps that isn't being done correctly. Are you referring to the same object instance in both cases?

Replies

1) You should call super.viewWillAppear. Probably not related.


2) Is "appSingleton" correctly defined and instantiated? Obviously you intend it to be a singleton, but perhaps that isn't being done correctly. Are you referring to the same object instance in both cases?

junkpile.


Thank you for your response. I have found a bug in my code that iterated through a table and changed the boolean value based on the last row in that table. Took me only 4 days to figure it out. 😊 Indeed, E=mc2 (Error = more code2).


Nevertheless, thank you so much for reminding me about calling super.viewWillAppear. I have completely ignored that.


Your support is greatly appreciated.


Best.