文件中没有任何内容,但是我立即将row1添加到我的数组中。 NSLog告诉我该数组是空的。为什么不将row1添加到数组中?据我所知,我所有的其他代码都很好。当我将硬值添加到数组中时,我的应用程序工作。现在我从文件加载,它不起作用。将一个对象添加到从文件中读取的数组中
- (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];
}
请帮忙!
由于提前,
马特
不要忘了`release`数组和字典,因为你每个人的使用`alloc`和创建`init`方法。请参阅Cocoa的内存管理编程指南:http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/MemoryMgmt/ – 2009-07-16 08:44:15