I am using global variables to access values from one viewcontroller to another, the problem i am facing is calling the global variable under viewdidload it will return null, but if i use the global variable under (ibaction) it works normally.
I am using global variables to access values from one viewcontroller to another, the
Share
The problem most likely has to do with the order of evaluation: the variable in question has not been initialized at the time of the
viewDidLoad:, but by the time an action is executed, the initialization is complete.You can try adjusting the timing by accessing your global from another callback that happens later than
viewDidLoad:, but to avoid the problem altogether, you could use a global singleton instead of a global variable. Make a separate class in which you keep your global state, include its header in places where you need to use it, and call its class methods to access your global variables, like this:Header:
Implementation:
Usage: