I have a UtilityApp and UITableViewController pushed from the FlipsideViewController. I have modified few cells in the UITableView to embed UITextField and UIButton(save button). The other table view cells would behave normally. On click of a normal UITableViewCell, i would again push the same UITableViewController which has the another set of UITableViewCells. Now my problem is, when i click on the save button i want to add a NSObject onto a NSMUtableArray. And when i go to the next controller(ie., the same UITableViewController) and click on the save button, again i want to add a NSObject to NSMutableArray. Thus the NSMutableArray behaves as a local cache for me. Hows it possible? Basically i want to declare the NSMutableArray somewhere outside the UITableViewController and keep adding NSObject instances to it. Please help me out.
Asked
Active
Viewed 443 times
1 Answers
1
You need a singleton class to use as a cache. For example, from this question:
@interface MySingleton : NSObject
{
}
+ (MySingleton *)sharedSingleton;
@end
@implementation MySingleton
+ (MySingleton *)sharedSingleton
{
static MySingleton *sharedSingleton;
@synchronized(self)
{
if (!sharedSingleton)
sharedSingleton = [[MySingleton alloc] init];
return sharedSingleton;
}
}
@end
Now just use [MySingleton sharedSingleton]
to get a shared reference to this object. Add methods to add objects to your NSMutableArray
.

Community
- 1
- 1

Steve McLeod
- 51,737
- 47
- 128
- 184