Method not seeing array as array
Method not seeing array as array
- Subject: Method not seeing array as array
- From: Michael Swan <email@hidden>
- Date: Wed, 2 Feb 2005 14:31:08 -0500
Hello all,
For some reason I have one method that can not see an NSArray outside itself. The other methods work fine wherever I set up the NSArray. I have included the code from my AppController class .h & .m files with comments in the problem method. The idea of the program is that there are 12 channels (MSChannel) each one has an NSSliderCell to control it's "intensity level" In addition there is a master slider that affects the levels of the channels proportionally. The levels are displayed in an NSMatrix of NSTextFieldCell s. Ultimately there will be more channels and the levels will go out a USB device to control lights. I figure if I can develop this program I will learn just about all I need to know about programming with objective-c and Cocoa (I realize it will be a very long time before this thing is "done"). I'm sure I have done something stupid that is causing the problem but I can't find it and would appreciate any help anyone has to offer.
Thank You,
Mike
/* AppController */
#import <Cocoa/Cocoa.h>
#import "MSChannel.h"
@interface AppController : NSObject
{
IBOutlet NSMatrix *channelDisplay;
IBOutlet NSMatrix *channelMatrix;
IBOutlet NSTextField *grandMaster;
NSArray *channelArray;
MSChannel *channel1;
MSChannel *channel2;
MSChannel *channel3;
MSChannel *channel4;
MSChannel *channel5;
MSChannel *channel6;
MSChannel *channel7;
MSChannel *channel8;
MSChannel *channel9;
MSChannel *channel10;
MSChannel *channel11;
MSChannel *channel12;
float masterLevel;
int maxChannels;
}
- (id)sender;
- (id)sender;
- (void) updateOutput;
@end
#import "AppController.h"
@implementation AppController
- (id)init
{
[super init];
channelArray = [[NSMutableArray alloc] init];
masterLevel = 100.0;
maxChannels = 12;
int theTag;
theTag = 0;
//init channels and put into array
//Putting the channelArray code here works for the updateOutput method but not
//for the changeChannelLevel: method
/* this code just makes the app crash still have to figure out the short way
while (theTag < maxChannels) {
channel = [[MSChannel alloc] init];
[channelArray addObject:channel];
NSLog(@"channel %@ added",[channelArray count]);
[channel release];
theTag++;
}
*/
return self;
}
- (id)sender
{
// get the floatValue from each slider cell and reduce it by the masterLevel, then put in channel
// sliderLevel * (masterLevel / 100)
int theTag;
float theLevel;
MSChannel *theChannel;
theTag = 0;
theLevel = 0;
//Have to do this all here for this method to see channelArray as an NSArray
//putting this code in init or awakeFromNib and I get
//[NSMachPort objectAtIndex:] selector not recgonized but other methods can tell that
//channelArray is an NSArray no matter where the code is
channel1 = [[MSChannel alloc] init];
channel2 = [[MSChannel alloc] init];
channel3 = [[MSChannel alloc] init];
channel4 = [[MSChannel alloc] init];
channel5 = [[MSChannel alloc] init];
channel6 = [[MSChannel alloc] init];
channel7 = [[MSChannel alloc] init];
channel8 = [[MSChannel alloc] init];
channel9 = [[MSChannel alloc] init];
channel10 = [[MSChannel alloc] init];
channel11 = [[MSChannel alloc] init];
channel12 = [[MSChannel alloc] init];
channelArray = [NSArray arrayWithObjects:channel1, channel2, channel3, channel4, channel5, channel6, channel7, channel8, channel9, channel10, channel11, channel12, nil];
[channel1 release];
[channel2 release];
[channel3 release];
[channel4 release];
[channel5 release];
[channel6 release];
[channel7 release];
[channel8 release];
[channel9 release];
[channel10 release];
[channel11 release];
[channel12 release];
while (theTag < maxChannels) {
theLevel = [[channelMatrix cellWithTag:theTag] floatValue] * (masterLevel / 100);
NSLog(@"theLevel = %f",theLevel);
theChannel = [channelArray objectAtIndex:theTag];
NSLog(@"theChannel = %i",[theChannel levelDMX]);
[theChannel setLevel:theLevel];
theTag++;
}
//now to update the output
[self updateOutput];
}
- (id)sender
{
masterLevel = [sender floatValue];
if (masterLevel < 100.0) {
[grandMaster setTextColor:[NSColor redColor]];
}
else {
[grandMaster setTextColor:[NSColor blackColor]];
}
[grandMaster setIntValue:masterLevel];
[self changeChannelLevel:sender];
}
- (void) updateOutput
{
int theTag;
theTag = 0;
while (theTag < maxChannels) {
[[channelDisplay cellWithTag:theTag] setIntValue:[[channelArray objectAtIndex:theTag] levelDMX]];
theTag++;
}
}
- (void) dealloc
{
[channelArray release];
[super dealloc];
}
@end
"As human beings our greatness lies not so much in being able to remake the world... as being able to remake ourselves" - Gandhi
_______________________________________________
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