我正在開發一個應用程序,我已經創建了plist,並且我正在向它添加數據..但是發生的情況是,每次數據被覆蓋並且以前的數據丟失了。我的意思是假設我添加一個名爲rocky的名字,下次我添加岩石,岩石被岩石覆蓋時,但我想要的是我的plist應該包含rocky和rock等等......我將數據添加到plist中用戶進入....動態添加數據到plist並填充tableview單元
這裏是我下面的代碼..
-(IBAction) myplist:(id) sender//the data is saved in a plist by clicking on this button
{
NSLog(@"mylist Clicked");
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:searchLabel.text];
// get paths from root direcory
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our Data/plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"];
// This writes the array to a plist file. If this file does not already exist, it creates a new one.
[array writeToFile:plistPath atomically: TRUE];
}
謝謝你索尼它的工作..和它正是我想要的......但現在..一個更多的問題,它在模擬器上工作..但如何使它在設備上運行..請幫助我。 – Ranjit
嗨索尼,我想問一件事,我應該如果我想在plist中只添加3個值,然後如果用戶添加更多,然後我會被覆蓋......如何做到這一點? – Ranjit