我正在尝试在实用程序模板应用程序的侧视图上显示一些数据,但应用程序在viewDidLoad方法结束时中止。我是iOS新手,可以做一些指导。
[super viewDidLoad];
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
NSString *thePath = [[NSBundle mainBundle] pathForResource:@"SavedData"ofType:@"plist"];
NSMutableDictionary *tempRootDictionary;
NSMutableArray *tempMutableArray;
if (thePath && (tempRootDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:thePath])) {
NSArray *keys = [tempRootDictionary allKeys];
int keysCount = [keys count];
tempMutableArray = [NSMutableArray arrayWithCapacity:keysCount];
for (int i=0; i<keysCount; i++) {
NSDictionary *dictionary = [tempRootDictionary objectForKey:[keys objectAtIndex:i]];
MyModelObject *aModelObject = [[MyModelObject alloc] init];
[aModelObject setName:[dictionary objectForKey:@"name"]];
[aModelObject setContext:[dictionary objectForKey:@"context"]];
[aModelObject setUsername:[dictionary objectForKey:@"username"]];
[aModelObject setPassword:[dictionary objectForKey:@"password"]];
[tempMutableArray addObject:aModelObject];
[aModelObject release];
[dictionary release];
}
} else {
return;
}
非常感谢帮助, 非常感谢......
答案 0 :(得分:1)
我在发布的代码中看到的唯一明显问题是:
[dictionary release];
在您设置字典的行上,您只获得对tempRootDictionary中对象的引用,而不是它的新alloc'd实例。所以不要发布它。删除该行。