iPhone Global Variable?

后端 未结 3 426
醉梦人生
醉梦人生 2020-12-10 00:30

I have two views with their own .h and .m files of course. How can I declare a bool (or any variable for that matter) in one view and be bale to access it in another view?

3条回答
  •  佛祖请我去吃肉
    2020-12-10 00:58

    Create a data model class. Instantiate it in your app delegate, and pass it along to your view controllers. Use Key-Value Observing to track changes to the model in your view controllers. See my answer here: How do I display and calculate numbers from a database on iPhone?

    "Why shouldn't I use globals? It can't hurt just this once." This is a bad habit to get into. Avoiding global variables makes your code easier to read and reuse, easier to extend, and easier to debug.

提交回复
热议问题