I am practicing using NSMutableArray. My program makes an array of 25 (NSBezierPath)s and displays them in the view. My program consists of the class BAButtonArray which is as follows:
BAButtonArray.h:
BAButtonArray.m:
IB information: I dragged a custom view from the palette and made it use BAButtonArray. I fixed the view inside the window so it would resize with constant margin.
Output: The view draws fine the first time (a grid of 25 green squares in lower left hand corner), but as soon as I try to resize the window, it has problems. The window does not resize at all. Here is the console output:
Can you tell me what's wrong with my code?
BAButtonArray.h:
Code:
#import <Cocoa/Cocoa.h>
@interface BAButtonArray : NSView {
NSMutableArray* pathArray;
}
@end
BAButtonArray.m:
Code:
#import "BAButtonArray.h"
@implementation BAButtonArray
-(void)awakeFromNib{
pathArray = [NSMutableArray arrayWithCapacity:25];
for(int i = 0 ; i<25 ; i++){
NSBezierPath* path = [NSBezierPath bezierPath];
[path appendBezierPathWithRect:NSMakeRect((float)(5+ 15*(i%5)), (float)(5 + 15*floor((float)i /5)) , (float)10, (float)10 )];
[pathArray addObject:path];
}
}
-(void)drawRect:(NSRect)rect{
[[NSColor blackColor] set];
[NSBezierPath fillRect:[self bounds]];
[[NSColor greenColor] set];
NSLog(@"starting. . .");
for(int i =0 ; i<25 ; i++){
[[pathArray objectAtIndex:i] fill];
}
NSLog(@"done.");
}
@end
IB information: I dragged a custom view from the palette and made it use BAButtonArray. I fixed the view inside the window so it would resize with constant margin.
Output: The view draws fine the first time (a grid of 25 green squares in lower left hand corner), but as soon as I try to resize the window, it has problems. The window does not resize at all. Here is the console output:
Code:
[Session started at 2010-10-27 14:48:05 -0700.]
2010-10-27 14:48:06.729 ButtonArray[6305:10b] starting. . .
2010-10-27 14:48:06.883 ButtonArray[6305:10b] done.
2010-10-27 14:48:26.474 ButtonArray[6305:10b] starting. . .
2010-10-27 14:48:26.476 ButtonArray[6305:10b] *** -[NSCFNumber objectAtIndex:]: unrecognized selector sent to instance 0x11cec0
2010-10-27 14:48:26.535 ButtonArray[6305:10b] *** -[NSCFNumber objectAtIndex:]: unrecognized selector sent to instance 0x11cec0
2010-10-27 14:48:26.552 ButtonArray[6305:10b] starting. . .
2010-10-27 14:48:26.565 ButtonArray[6305:10b] *** -[NSCFNumber objectAtIndex:]: unrecognized selector sent to instance 0x11cec0
2010-10-27 14:48:26.586 ButtonArray[6305:10b] *** -[NSCFNumber objectAtIndex:]: unrecognized selector sent to instance 0x11cec0
2010-10-27 14:48:28.121 ButtonArray[6305:10b] starting. . .
2010-10-27 14:48:28.159 ButtonArray[6305:10b] *** -[NSCFNumber objectAtIndex:]: unrecognized selector sent to instance 0x11cec0
2010-10-27 14:48:28.162 ButtonArray[6305:10b] *** -[NSCFNumber objectAtIndex:]: unrecognized selector sent to instance 0x11cec0
Can you tell me what's wrong with my code?