Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

medasmx

macrumors member
Original poster
Nov 9, 2008
89
0
I am resubmitting this with the code to my previous program, which worked. It had three text fields and two buttons. The first text field strings inputted strings to go into an array. The first button was pushed to input each member of the array. The second text field and button inputted an integer to query array members, by index. The output appeared in the third text field. Below is the code.

#import "firsttryarrayadam.h"


@implementation firsttryarrayadam


-(id)init
{
[super init];
myArray=[[NSMutableArray alloc]init];
return self;
}
-(IBAction)asmbutton1:(NSButton*)sender;
{
myInputArray=[input1 stringValue];
[input1 setStringValue:mad:""];
[myArray addObject:myInputArray];
}

-(IBAction)asmbutton2:(NSButton*)sender;
{
myInt=([input2 intValue]-1);
mySecondString=[myArray objectAtIndex:myInt];
[output setStringValue:mySecondString];
}
@end

The only difference in the code that follows here is that I am adding a NSPopUpButton, so that you can do various things with the array, not just query by index. In the program below you are supposed to query either the index or the total number in the array. The idea with writing the second program was to figure out how to use NSPopUpButton.

When trying to build-and-go I get the errors below:

1. itemTitleAtIndex undeclared
2. error prior to : -- in reference to
if (itemTitleAtIndexopupButton isEqual:mad:"index")
3. error before else.

#import "firsttryarrayadam.h"


@implementation firsttryarrayadam


-(id)init
{
[super init];
myArray=[[NSMutableArray alloc]init];
return self;
}
-(IBAction)asmbutton1NSButton*)sender;
{
myInputArray=[input1 stringValue];
[input1 setStringValue:mad:""];
[myArray addObject:myInputArray];
}

-(void)awakeFromNib
{
NSPopUpButton*popupButton = [[[NSPopUpButton alloc] initTextCell:mad:""] autorelease];
[popupButton setEditable:YES]; [popupButton setBordered:NO];
[popupButton addItemsWithTitles:[NSArray arrayWithObjects:mad:"index", @"number", nil]];
}

-(IBAction)popupButtonNSPopUpButton*)sender;
{
if (itemTitleAtIndexopupButton isEqual:mad:"index")
{
myInt=([input2 intValue]-1);
[input2 setStringValue:mad:""];
mySecondString=[myArray objectAtIndex:myInt];
[output setStringValue:mySecondString];
}
else if (itemTitleAtIndexopupButton isEqual:mad:"number")
{
[output setObjectValue:[count myArray]];
}
}
@end

As previously stated, the awakeFromNib portion of the program I borrowed from a prior thread regarding NSPopUpButtonCell. I modified it, and probably am using it incorrectly. Thanks for any help.

Adam
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.