interface file…
implementation file...
Logging the contents of the mutableArray, myArray, it is null. If you initialize the mutable array within the action "addText" the array is not null, but then it cannot be used in the action "programLabel". As a second exercise, I tried to create a second mutable array locally (within addText), then adding its contents to myArray, using arrayWithArray, etc, but that hasn't worked either. I have google'ed extensively, and have been surprised not to find a sample addressing this online or in books, because it seems like it would be used commonly. In any case, any help is appreciated.
Code:
IBOutlet UILabel*label;
NSMutableArray*myArray;
IBOutlet UITextField*someText;
}
-(IBAction)programLabel:(id)sender;
-(IBAction)addText:(id)sender;
implementation file...
Code:
- (id)init {
if (self == [super init]) {
myArray = [[NSMutableArray alloc] initWithObjects: nil];
myArray = [NSMutableArray arrayWithCapacity:50];
}
return self;
}
-(IBAction)programLabel:(id)sender{
label.text=[NSString stringWithFormat:@"%@",[myArray objectAtIndex:0]];
}
-(IBAction)addText:(id)sender{
[myArray insertObject:[NSString stringWithFormat:@"%@", someText.text] atIndex:[myArray count]];
NSLog(@"%@",[myArray objectAtIndex:0]);
}
Logging the contents of the mutableArray, myArray, it is null. If you initialize the mutable array within the action "addText" the array is not null, but then it cannot be used in the action "programLabel". As a second exercise, I tried to create a second mutable array locally (within addText), then adding its contents to myArray, using arrayWithArray, etc, but that hasn't worked either. I have google'ed extensively, and have been surprised not to find a sample addressing this online or in books, because it seems like it would be used commonly. In any case, any help is appreciated.