views:

52

answers:

1

Whenever I try to add something to my array in the method nothing gets added to the array. I'm wanting it to when you press the button it will add a new object to the array.

//  JBNumberGeneration.h

#import <Cocoa/Cocoa.h>


@interface JBNumberGeneration : NSObject {
 IBOutlet NSTextField *displayLabel;
 int randNum;
 int level;
 int i;
 NSMutableArray* userNumSequence;
}

-(IBAction)logSequenceNumber:(id)sender;

@end


//  JBNumberGeneration.m

#import "JBNumberGeneration.h"


@implementation JBNumberGeneration

-(IBAction)logSequenceNumber:(id)sender{
  NSString *titleOfButton = [sender title];
 int sequenceNumber = [titleOfButton integerValue];

 int count = [userNumSequence count];
 i++;

 [userNumSequence addObject:[NSNumber numberWithInteger:sequenceNumber]];

 NSLog(@"Array size: %i", count);
    }
    @end
A: 

Have you initialized the array somewhere using something like userNumSequence = [NSMutableArray arrayWithCapacity:0]; I could not see that in your code as that would cause nothing to get added.

abdollar
Ok I added it in but it seems to create the array and then delete after the function is finished.
JoeMBlair
Added it in after "int sequenceNumber = [titleOfButton integerValue];"
JoeMBlair
initialize the array in init for the class JBNumberGeneration
abdollar
- (id) init{ if (self = [super init]) { userNumSequence = [NSMutableArray arrayWithCapacity:0]; } return self;}
abdollar
Thank you for your help, I'm quite new to objective-C.
JoeMBlair