0
我正在使用核心數據,我需要通過請求的結果循環,在循環中創建幾個自定義對象並將它們存儲在NSMUtableArray中,以便我可以將它發送到另一個視圖來提要一個UI組件。這是我在做什麼:從NSFetchRequest問題獲取NSString問題
NSMutableArray *persons = [[NSMutableArray alloc] init];
NSError *error = nil;
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Person" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for (NSManagedObject *info in fetchedObjects) {
ToggleButtonInfo *btn = [[ToggleButtonInfo alloc] init];
NSString *personName = [NSString stringWithFormat:@"ww %@", [info valueForKey:@"name"]];
NSLog(@"pn: %@", personName);
[btn setButtonInfo:personName];
[persons addObject:btn];
}
[fetchRequest release];
return persons;
循環工作得很好,信息在那裏。問題是,我得到一個「EXC_BAD_ACCESS」在我的組件,如果我使用:
[info valueForKey:@"name"]
,如果我做這樣的事情:
[btn setButtonInfo:@"something else here"];
一切工作正常。所以它看起來像信息已被解除分配,這是導致錯誤,對吧?我嘗試使用stringWithFormat創建scring,但它不起作用,同樣的錯誤。
想法?
是的,稍後在顯示按鈕的位置出現錯誤。問題:爲什麼泄漏?是不是由NSMutableArray擁有?當NSMutable數組被解除分配時它不會被釋放嗎? – oscarm 2011-02-08 17:14:06