NSMutableArray accessing issue.

Posted by Danegraphics on Stack Overflow See other posts from Stack Overflow or by Danegraphics
Published on 2010-04-09T05:17:39Z Indexed on 2010/04/09 5:23 UTC
Read the original article Hit count: 169

Filed under:
|
|
|

I've searched and have no answer. I've created an NSMutableArray and am getting an EXC_BAD_ACCESS error in one place of access. Here. This is declaring in the .h file:

NSMutableArray *buttons;
...
@property (nonatomic, retain)NSMutableArray *buttons;

And this is the synthesizing and implimenting:

@synthesize buttons;
...
- (id)init {
    self = [super init];
    if(self != nil) {
        buttons = [[NSMutableArray alloc] init];
    }
    return self;
}
...
-(void)addButtonWithImage:(Image*)image {
    Image *button = image;
    [buttons addObject:button];
    [button release];
}
...
-(void)replaceButtonAt:(int)num with:(Image*)image {
    Image *button = image;
    [buttons replaceObjectAtIndex:num withObject:button];  <<===EXC_BAD_ACCESS
    [button release];
}

But when I use this:

-(void)renderButton:(int)num atPoint:(CGPoint)point center:(BOOL)center{
    Image *button = [buttons objectAtIndex:num];
    [button renderAtPoint:point centerOfImage:center];
}

It works

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about arrays