Il n'y a rien dans le fichier, mais j'ajoute row1 à mon tableau juste après. NSLog me dit que le tableau est vide. Pourquoi row1 n'est-il pas ajouté au tableau? Tous mes autres codes vont bien pour autant que je sache. Mon application a fonctionné quand j'ai mis des valeurs dures dans le tableau. Maintenant que je charge à partir d'un fichier, cela ne fonctionne pas.Ajout d'un objet à un tableau lu à partir d'un fichier
- (void)viewDidLoad {
//array value
//NSMutableArray *array;
NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
NSMutableArray *array/*array*/ = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
NSDictionary *row1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"Study", @"Task", @"2 hours", @"Length", @"4", @"Hours", @"0", @"Minutes", @"15", @"Tiredness", nil];
[array addObject: row1];
self.tasks = array;
NSLog(@"The contents of the array (file exists) is %@", array);
[array release];
[myTableView reloadData];
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:app];
[super viewDidLoad];
}
Aidez-nous!
Merci à l'avance,
Matt
Ne pas oublier de 'release' le tableau et le dictionnaire, puisque vous avez créé chacun d'entre eux en utilisant' alloc' et un Méthode 'init'. Voir le Guide de programmation de gestion de mémoire pour Cocoa: http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/MemoryMgmt/ –