Oddness with NSArray (Most likely some other stupid mistake)
Oddness with NSArray (Most likely some other stupid mistake)
- Subject: Oddness with NSArray (Most likely some other stupid mistake)
- From: James Farwell <email@hidden>
- Date: Sat, 9 Nov 2002 14:50:47 -0800
First off I just want to state for the record that I'm still fairly new
to Objective-C/Cocoa, so if I'm doing something totally stupid that is
the result of inexperience, I apologize. I have an app with a
controller class that manages a list of smaller controller classes for
external nibs (sort of like a plug-in type situation). The only real
complexity is that the external nibs have a button to add a new sub
controller instance to the list. I am having problems with the
following code:
@implementation MyController
- (void)awakeFromNib
{
children = [NSMutableArray arrayWithCapacity:10];
[self addNewChild];
}
- (void)addNewChild
{
// Create a new sub controller and add it to the array
MySubController *child = [[MySubController alloc]
initWithParent:self];
[children addObject:child];
// ...Code to make child display its view...
}
- (NSMutableArray *)children
{
return children;
}
@end
-----------
@implementation MySubController
- (id)initWithParent:(MyController *)controller
{
self = [super init];
if (self == nil) return nil;
parent = controller;
// ...Code to load nib file from bundle...
return self;
}
- (IBAction)addChild:(id)sender
{
[parent addNewChild];
}
@end
-------
Now the initial code works great, and I get a display with one of the
child views. However, when I click on the button to add a new child,
the app dies on the call to "[children addObject:child];" with
EXC_BAD_ACCESS. I'm fairly sure that a new child is being allocated
each time, and and children isn't being modified in anyway in between
these calls, but obviously there is some odd memory space voodoo going
on here. Anyone have any ideas?
Thanks!
- James
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.