【问题标题】:EXC_BAD_ACCESS in viewDidLoad of FlipsideViewControllerFlipsideViewController 的 viewDidLoad 中的 EXC_BAD_ACCESS
【发布时间】:2010-11-23 02:46:18
【问题描述】:

我试图在实用程序模板应用程序的反面视图上显示一些数据,但应用程序在 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;
}

非常感谢您的帮助, 非常感谢...

【问题讨论】:

  • MyModelObject 中有什么可疑之处?
  • 您是否已将范围缩小到导致错误的确切行?至少[dictionary release]; 行是错误的,应该删除。你没有分配 dictionary 所以不要释放它。

标签: iphone objective-c ios


【解决方案1】:

我在发布的代码中看到的唯一明显问题是:

[dictionary release];

在您设置字典的那一行,您只会获得对 tempRootDictionary 中对象的引用,而不是它的新分配实例。所以不要释放它。删除该行。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-01
  • 2011-03-26
  • 1970-01-01
  • 1970-01-01
  • 2011-09-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多