简体   繁体   中英

Access variables IN singleton class in iOS

My app basically takes the name, phone number, etc and stores it in a plist. I have a button that stores all the data in a plist(a separate class for it "FirstClass") and a button that would load all the data and open it in a table view. So I decided to create a singleton class that would store the data and would be able to manipulate the data and all the other classes can access it from the singleton class. But the singleton class is a subclass on NSObject, so I can't create outlets for the textfields of name, phone number etc in my singleton class so I need to create it in my "FirstClass", how do I access the text in these fields in my singleton class? By creating normal class instance of "FirstClass"?

The singleton you are describing acts as your data model (the 'M' part of MVC). Outlets belong in your view controller (the 'C' part).

So, specifically, your view controller should handle the button being pressed and then tell the data model singleton what to do. Once the data is loaded, the singleton would do something like post a notification (or execute a block) to tell the view controller that the table should be reloaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM