最善の方法は、tableView のデータソースをドキュメント ディレクトリの .plist ファイルに保存することです。次に、viewWillAppear メソッドで、tableView のデータソースを .plist ファイルに設定します (利用可能な場合)。
通常、データソースは NSDictionary/Mutable または NSArray/Mutable です。どちらもドキュメントディレクトリに書き込む方法があり、次のように取得できます。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
ドキュメント ディレクトリにリストの 1 つを書き込む方法は次のようになります。
BOOL saved = [datasource writeToPath:[documentsDirectory stringByAppendingPathComponent:@"savedDatasource.plist"] atomically:YES];
if (saved) {
//saved datasource to .plist file.
}
else if (!saved) {
//did not save;
}
ドキュメント ディレクトリから plist をロードするには、まず plist があるかどうかを確認する必要があります。
if ([[NSFileManager defaultManager] fileExistsAtPath:[documentsDirectory stringByAppendingPathComponent:@"savedDatasource.plist"]]) {
countryMArray = [[NSMutableArray alloc] initWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:@"savedDatasource.plist"]];
}
else {
//it is not there, we need to write it to the documents directory
[datasource writeToPath:[documentsDirectory stringByAppendingPathComponent:@"savedDatasource.plist"] atomically:YES];
}
幸運を!