addObject failing
addObject failing
- Subject: addObject failing
- From: Jeff Childers <email@hidden>
- Date: Mon, 22 Aug 2005 17:28:17 -0500
the code looks through the windows views and finds all the steppers and
in theory should be adding them to an array. Unfortunately it exits due
to signal 10 when I call count on the array.
--.h--
#import <Cocoa/Cocoa.h>
@interface KeyEvents : NSView
{
NSMutableArray *stepperArray;
}
- (void)findSteppers;
- (void)checkView:(NSView *)aView;
- (void)checkStepper:(NSStepper *)aStepper;
- (void)setSteppers:(int)newValue;
@end
--.m--
#import "KeyEvents.h"
@implementation KeyEvents
- (id)initWithFrame:(NSRect)frameRect
{
[super initWithFrame:frameRect];
return self;
}
- (void)drawRect:(NSRect)rect
{}
//recieve the keypresses first
- (BOOL)acceptsFirstResponder {
return YES;
}
- (void)findSteppers
{
// start looking for the steppers
stepperArray = [ [NSMutableArray alloc] init];
// Check all the views recursively
[stepperArray removeAllObjects];
[self checkView:[[self window] contentView] ];
//#########################################
/// dies right here
NSLog(@"array count %@",[stepperArray count]);
//#########################################
}
- (void)checkView:(NSView *)aView
{
id view;
NSEnumerator *enumerator;
// Log which aView is being processed, see PB for output
NSLog(@"checkView(%@)\n",aView);
// Process the aView if it's an NSStepper
if ([aView isKindOfClass: [NSStepper class] ]) {
[self checkStepper: (NSStepper *)aView];
return;
}
// Recursively check all the subviews in the window
enumerator = [ [aView subviews] objectEnumerator];
while(view = [enumerator nextObject]){
[self checkView:view];
}
}
- (void)checkStepper:(NSStepper *)aStepper
{
NSLog(@">>> addObject %@", aStepper);
//// should be adding the stepper to the array
[stepperArray addObject:aStepper];
NSLog(@"current inc %@",[stepperArray count]);
}
- (void)flagsChanged:(NSEvent *)event{
if (! stepperArray){
[self findSteppers];
}
NSLog(@"%@",[stepperArray count]);
if (([event modifierFlags] & NSCommandKeyMask) != 0){
//NSLog(@"10");
[self setSteppers:10];
}
else{
[self setSteppers:1];
//NSLog(@"1");
}
}
- (void)setSteppers:(int)newValue
{
NSLog(@"%@",stepperArray);
id stepper;
NSEnumerator *enumerator2;
enumerator2 = [stepperArray objectEnumerator];
while(stepper = [enumerator2 nextObject]){
[stepper setIncrement:newValue];
//NSLog(@"current inc %@",[stepper increment]);
}
}
- (void)dealloc
{
NSLog(@"dealloc");
[stepperArray release];
[super dealloc];
}
@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden