cocoa NSArray

Discussion in 'Mac Programming' started by medasmx, Dec 6, 2008.

  1. medasmx macrumors member

    Joined:
    Nov 9, 2008
    #1
    I took a lot of this example from Hillegass "speakline". What I wrote has three textboxes and two buttons. The idea is to input into the first box, names (or strings), to go into an array. In the second box you input the integer whose array element you are trying to see. I got the program to run, but it stops at the second input (that is, it allows you to input the names, but when you put the integer in it stops). Below is my code.

    Code:
    #import <Cocoa/Cocoa.h>
    
    
    @interface firsttryarrayadam : NSObject {
    IBOutlet NSTextField*input1;
    IBOutlet NSTextField*input2;
    IBOutlet NSTextField*output;
    NSMutableArray*myArray;
    NSString*myInputArray;
    NSString*mySecondString;
    NSNumber*myInt;
    }
    -(IBAction)asmbutton1:(NSButton*)sender;
    -(IBAction)asmbutton2:(NSButton*)sender;
    
    @end
    
    #import "firsttryarrayadam.h"
    
    
    @implementation firsttryarrayadam
    
    
    -(id)init
    {
    [super init];
    myArray=[[NSMutableArray alloc]init];
    return self;
    }
    -(IBAction)asmbutton1:(NSButton*)sender;
    {
    myInputArray=[input1 stringValue];
    [myArray addObject:myInputArray];
    }
    
    -(IBAction)asmbutton2:(NSButton*)sender;
    {
    myInt=[input2 intValue];
    mySecondString=[myArray objectAtIndex:myInt];
    [output mySecondString];
    }
    @end
    The error that comes out is the following --
    2008-12-06 21:06:49.106 firsttryarray[260:10b] *** -[NSTextField mySecondString]: unrecognized selector sent to instance 0x127e70

    Thanks.

    Adam
     
  2. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #2
    It looks like you're trying to send a 'mySecondString' method to your 'output' NSTextField:

    [output mySecondString];

    Do you want to print the 'mySecondString' string to your 'output' NSTextField?

    [output setStringValue: mySecondString];

    ?
     

Share This Page