Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何将NSMutableArray用作本地缓存_Objective C_Ios_Cocoa Touch - Fatal编程技术网

Objective c 如何将NSMutableArray用作本地缓存

Objective c 如何将NSMutableArray用作本地缓存,objective-c,ios,cocoa-touch,Objective C,Ios,Cocoa Touch,我从FlipsideViewController推送了一个UtilityApp和UITableViewController。我修改了UITableView中的几个单元格,以嵌入UITextField和UIButton(保存按钮)。其他表视图单元格将正常工作。单击一个普通的UITableViewCell,我会再次推送具有另一组UITableViewCell的同一个UITableViewController。现在我的问题是,当我单击save按钮时,我想将NSObject添加到NSMUtableArr

我从FlipsideViewController推送了一个UtilityApp和UITableViewController。我修改了UITableView中的几个单元格,以嵌入UITextField和UIButton(保存按钮)。其他表视图单元格将正常工作。单击一个普通的UITableViewCell,我会再次推送具有另一组UITableViewCell的同一个UITableViewController。现在我的问题是,当我单击save按钮时,我想将NSObject添加到NSMUtableArray中。
当我转到下一个控制器(即同一个UITableViewController)并单击save按钮时,我想再次向NSMutableArray添加一个NSObject。因此,NSMutableArray对我来说就像一个本地缓存。怎么可能呢?基本上,我想在UITableViewController之外的某个地方声明NSMutableArray,并继续向其中添加NSObject实例。请帮助我。

您需要一个单例类来用作缓存。例如,来自:


现在只需使用
[MySingleton sharedSingleton]
获取此对象的共享引用。添加方法将对象添加到
NSMutableArray

您需要一个单例类作为缓存使用。例如,来自:

现在只需使用
[MySingleton sharedSingleton]
获取此对象的共享引用。添加方法将对象添加到
NSMutableArray

@interface MySingleton : NSObject
{
}

+ (MySingleton *)sharedSingleton;
@end

@implementation MySingleton

+ (MySingleton *)sharedSingleton
{
  static MySingleton *sharedSingleton;

  @synchronized(self)
  {
    if (!sharedSingleton)
      sharedSingleton = [[MySingleton alloc] init];

    return sharedSingleton;
  }
}

@end