Im quite new to iphone development, I want to create a mutable array which can access and populate from different view controllers. How can I do it? If you can please give me a sample code
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
In most cases its not needed nor helpfull to use global variables. If you have to use them the easiest way is to put the array in your AppDelegate.
You can access the Array (named array in AppDelegate here) with :
In MVC, you have views, controllers and models. You should push as much down as possible. Multiple views and controllers can operate on the same model that controls the data and business logic.
In your case, you have a simple set of shared data - a mutable array.
I would suggest create a class that contains that mutable array and exposes methods. A common pattern is for that class to be a singleton.
So, the multiple controllers would do.
Then both controllers can operate on it.
Here's a good article on the topic: http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html
singleton from apple: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html#//apple_ref/doc/uid/TP40002974-CH4-SW32
Hope that helps.
In your
@interface YourClass
decline array:In your
@implementation YourClass
write this:If you will have reference
yourClassVariable
to that object you can access that variable using[yourClassVariable publicArray];
oryourClassVariable.publicArray;