views:

57

answers:

3

Hi All In my application one is mainviewcontroller which is subclass of uiTableviewcontroller holds data from plist when clicked on a particular cell its displays detailviewcontroller(dvc) which is subclass of uiviewcontroller. dvc holds textfield & button .actually when i clicked on button i write textfield's text on tableviewcell through plist but it is actually write data temporary but i want to write data permanently on tableview what can i do for that .its a navigation based application?

A: 

could you show us some code?

What is the code for the action button? How do you reload the table view?

I'm guessing you are reading a plist into a NSDictionary? Then loading the tableviews cell.text from the values in the dictionary? When you push the button do you write the textfield text to the NSDIctionary? Do you remember to write the NSDictionary back to the plist?

Larsaronen
NSString *path = [[NSBundle mainBundle] pathForResource:@"listData" ofType:@"plist"]; //here nes is my mainviewcontroller object. nes.plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; [nes.plistDict setValue:txtName.text forKey:@"col1"]; [nes.plistDict writeToFile:path atomically: YES]; [nes.tableView reloadData];
suchita
A: 

Okay. How do you load youre tableview cells? Are you sure the value for col1 is of NSString type? You should probably use setObject: forKey: instead of SetValue: forKey:.. Does the tableview not update at all or is it just that it is not saved after you quit? Are you testing on simulator or device? The application bundle is a readonly directory on device but not in simulator. you should use:

NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *plistPath = [rootPath stringByAppendingPathComponent:@"listData.plist"];

Larsaronen
suchita
A: 

Try this:

Loading the plist to dictionary:

//Get the path to documents directory
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *plistPath = [rootPath stringByAppendingPathComponent:@"listData.plist"];

//if the file does not exist in documents directory, then load from the bundle.
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
   plistPath = [[NSBundle mainBundle] pathForResource:@"listData" ofType:@"plist"];
}

//load plist into NSMutableDictionary.
nes.plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath]; 

Saving dictionary to plist:

//Get the path to documents directory
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *plistPath = [rootPath stringByAppendingPathComponent:@"listData.plist"];

//Write to documents directory! NOT bundle!!
[nes.plistDict writeToFile:plistPath atomically: YES]; 

Also use: [nes.plistDict setObject:txtName.text forKey:@"col1"]; Not: [nes.plistDict setValue:txtName.text forKey:@"col1"];

If this does not help can I see youre cellForRowAtIndexPath in mainviewcontroller?

Larsaronen
thanx Larsaronen it's works
suchita