开发者

how to access an object from another function

In viewDidLoad, an object is created. In some other function, I want to do something with the object, but outside of viewDidLoad, the object is not recognized. How can I access the object from ot开发者_StackOverflow中文版her functions?


you have to declare that object in your view controllers header (not in viewDidLoad). you can initialize the object in viewDidLoad. Now it will be visible in every method (not function) within that class. ;)


If you want the object to be accessable by all other variables in the same level, you'll have to declare it in the same level as viewDidLoad and the other function.

//start of program
            //declare the object
            //declare viewDidLoad
              //--
            //declare other function
              //--
//end of program
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜