views:

67

answers:

2

Why my add items dont save on memory? When I back to RootViewController my list disappear, What happened ?

Code for add and work fine...

- (IBAction) addButtonPressed: (id)sender {
 NSLog(@"Add button pressed!");

 addPosto *addposto = [[addPosto alloc] initWithNibName:@"postoDictionary" bundle:nil];
 UINavigationController *addNavCon = [[UINavigationController alloc] initWithRootViewController:addposto];
 addposto.postoArray = self.poscomb;
 [self presentModalViewController:addNavCon animated:YES];
 [addposto release];
 [addNavCon release];

}

On RootViewController select row "Meus Postos"

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

   postoLista *codigo = [[postoLista alloc] initWithNibName:@"postoLista" bundle:nil];
   [self.navigationController pushViewController:codigo animated:YES];
   [codigo release];

}

So I need to know how I archieve list on memory after add items, thanks for attention!

Eduardo Parucker.

A: 

Hi Jordan,

Sorry about code, let try again...

 - (void)viewDidLoad {

   [super viewDidLoad];

self.navigationItem.rightBarButtonItem = self.editButtonItem;

[self setTitle:@"Meus Postos"];

NSString *path = [[NSBundle mainBundle] pathForResource:@"combustiveis" ofType:@"plist"];
NSMutableArray* tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
self.poscomb = tmpArray;
[tmpArray release];

UIApplication *app = [UIApplication sharedApplication];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:app];

}

 - (void) applicationWillTerminate: (NSNotification *)notification {

NSString *path = [[NSBundle mainBundle]
                  pathForResource:@"combustiveis" ofType:@"plist"];
[self.poscomb writeToFile:path atomically:YES];

}

I need instance something on delegate ? I really need this information, thanks!

Eduardo Parucker.

parucker
So your problem is that `[self.poscomb writeToFile:path atomically:YES];` does not write the data to the disk? Have you tried to debug this issue? Do you have the correct data in self.poscomb? Your question is a bit vague.
Stelian Iancu
my question is exactly what you described, just do not know if the nscoding would be the solution, I'm using [self.poscomb WriteToFile: path atomically: YES] to be archived items, but that's not what this is happening and poscomb an NSMutableArray that feeds nsdictionary (plist), thanks for the help.
parucker
A: 

I talk to Leonardo of Instants Games on Brazil he implement a singleton and resolved my problem, so I think thats it! thanks for all helps!

parucker