0

私の問題は、iPhone/iPad 用の Web ブラウザーを作成していて、ブックマークを追加したときにブックマーク システムと tableview plist データの更新をテストしたことです。シミュレーター側で動作しますが、iPhone を使用してアプリをテストしたとき、更新テーブルビューが表示されません。xcode を介してデータを plist に追加しました。追加したデータは iPhone に表示されますが、新しいものを表示するように更新されません。アプリ経由で入力するエントリ plist ファイルは「bookmarks.plist」と呼ばれます。問題は何ですか?

ここで、bookmarks.plist に書き込むコード

NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *plistPath = [documentDirectory stringByAppendingPathComponent:@"bookmarks.plist"];

if (![fileManager fileExistsAtPath:plistPath]) {
    plistPath = [[NSBundle mainBundle] pathForResource:@"bookmarks" ofType:@"plist"];
    //[[NSFileManager defaultManager] copyItemAtPath:plistPath toPath:plistPath error:NULL];
}

NSMutableArray *dataRoot = [NSMutableArray arrayWithContentsOfFile:plistPath];

NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
[item setObject: _titleField.text forKey:@"title"];
[item setObject:_urlField.text forKey:@"url"];

[dataRoot addObject:item];
[dataRoot writeToFile:plistPath atomically:YES];
4

1 に答える 1

0

looks like your plist file is not in documents directory on device, neither you are copying it there at runtime (that LOC is commented).

so plistPath will be nil

if your plistPath is created from NSBundle,
[dataRoot writeToFile:plistPath atomically:YES]; file will not be written as bundle resources are read-only.

this info should help you in some way.

于 2012-12-02T19:48:41.807 に答える