0

このコードは、plistをdocumentsディレクトリに保存するためにうまく機能します。

- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.addButtonItem;
NSString *path = [[NSBundle mainBundle] pathForResource:@"TitleArray" ofType:@"plist"];
NSMutableArray *tmpArray = [[NSMutableArray alloc]initWithContentsOfFile:path];
self.titles = tmpArray;
[tmpArray release];

//TESTING NEW CODE FOR SAVING TO DOC DIR
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *docDirPath = [documentsDirectory stringByAppendingPathComponent:@"TitleArray.plist"];

NSFileManager *fileManager = [NSFileManager defaultManager];

if(![fileManager fileExistsAtPath: docDirPath])
{
    NSString *bundle = [[NSBundle mainBundle] pathForResource:@"TitleArray" ofType:@"plist"];

    [fileManager copyItemAtPath:bundle toPath:docDirPath error:&error];

                        NSLog(@"plist is copied to Directory");
                        }

plistをアプリにロードする方法がわかりませんでした。

誰か助けてもらえますか?ありがとう。

4

3 に答える 3

4
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"TitleArray.plist"];
NSArray * myList = [NSArray arrayWithContentsOfFile:path];
NSMutableArray *tmpArray = [myList mutableCopy];
self.titles = tmpArray;
[tmpArray release];

動作しませんでしたか?

于 2010-11-27T04:23:00.083 に答える
0

アプリのメインバンドルに含まれているplistを上書きする方法を尋ねている場合は、それができないことを知っておく必要があります。詳細については、この質問をご覧ください。 アプリケーションバンドル内のファイルを更新できますか?

于 2010-11-27T04:28:35.200 に答える