我試圖寫一個清單,包含在我的項目(Deck.txt)一個文本文件中的相關代碼如下:寫入字符串使用的Xcode爲iPhone開發的文本文件
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Deck" ofType:@"txt"];
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];
deck = [[NSString alloc]initWithFormat: @"%@\n%@ %@",file, txtQuantity.text, cardName];
//[deck writeToFile:filePath atomically:YES encoding:NSStringEncodingConversionAllowLossy error:nil];
[fileHandle writeData:[deck dataUsingEncoding:NSUTF8StringEncoding]];
[fileHandle closeFile];
但是,當我運行代碼時,它不會保存到文本文檔中,或者至少不會保存在我的項目中。它仍然會創建列表並從文件中讀取我正在嘗試寫入的所有數據,但是當關閉程序時,不會對文本文檔進行更改。非常感激任何的幫助。
您的鏈接返回此帖。 – achi 2013-07-03 22:45:18
那裏。固定。 ;-) – 2013-07-04 04:41:11