2009-06-09 13 views
1

私が書いているアプリケーションでは、フォーチュンクッキーのリストをプロパティリストに書き出しようとしています。シミュレータでは、これは期待どおりに動作し、すべてが素晴らしいです。 iPodのタッチで私はそれがうまくリストから読み取るが、それはリストを更新することはありません。iPod Touchのプロパティリストに書き込むことはできませんが、シミュレータでは機能します

シミュレータを使用したプロパティリストの更新とiPod Touchの使用に違いはありますか?

if(indexEdit == [data count]) 
    { 
     NSString *temp = [NSString stringWithFormat:@"%@", textField.text]; 
     [self.data addObject:temp]; 
    } 
    else 
    { 
     NSString *temp = [NSString stringWithFormat:@"%@", textField.text]; 
     [data replaceObjectAtIndex:indexEdit withObject:temp]; 
    } 
    NSString *errorDesc; 
    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Fortunes" ofType:@"plist"]; 
    NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:data format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc]; 
    if (plistData) 
    { 
     [plistData writeToFile:bundlePath atomically:YES]; 
    } 
    else 
    { 
     NSLog(errorDesc); 
     [errorDesc release]; 
    } 

答えて

4

あなたのアプリケーションバンドルはかなり読まれていると考えられます。ファイルを書きたい場合は、次のような "Documents"フォルダに入れてください:

NSArray *savePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSMutableString *savePath = [NSMutableString stringWithString:[savePaths objectAtIndex:0]]; 
[savePath appendString:@"/Fortunes"]; 

// blah blah 

[plistData writeToFile:savePath atomically:YES]; 
+0

私はFortunesの代わりにFortunes.plistを使っていましたが、動作します。ありがとうございました。 –

+0

私はします:NSString *ファイル名= [savePathstringByAppendingPathComponent:@ "Fortunes.plist"]; 代わりにスラッシュを心配する必要があります –

+0

良い点、ベニー。私の防衛の中で、私は最初にココアを学び始めたときにそのコードを書きました! –

関連する問題