• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Oddness with NSArray (Most likely some other stupid mistake)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Oddness with NSArray (Most likely some other stupid mistake)
      • From: Andreas Mayer <email@hidden>
    • Re: Oddness with NSArray (Most likely some other stupid mistake)
      • From: Ondra Cada <email@hidden>
  • Prev by Date: Making my app use FileWrappers (Document Bundles) as the file type...
  • Next by Date: Re: Cocoa really needs to be thread-safe
  • Previous by thread: Making my app use FileWrappers (Document Bundles) as the file type...
  • Next by thread: Re: Oddness with NSArray (Most likely some other stupid mistake)
  • Index(es):
    • Date
    • Thread