views:

41

answers:

1

I have an array initialized

- (void) viewDidLoad {
    NSArray *myArray = [NSArray arrayWithObjects:
                   [NSArray arrayWithObjects:@"item 1-1", @"item 1-2", nil],
                   [NSArray arrayWithObjects:@"item 2-1", @"item 2-2", nil],
                   [NSArray arrayWithObjects:@"item 3-1", @"item 3-2", nil],
                   nil];
}

- (IBAction) someButtonPressed {
    NSString *text = // and here I can't figure out how to actually access the value needed
    [someLabel setText:text];
}

I need to set someLabel text to the "item 1-2" value, for instance. How can I do that?

+2  A: 
[someLabel setText:[[myArray objectAtIndex:0] objectAtIndex:1];

You do need to make myArray visible to other methods -- placing it in your class declaration is the easiest way. Don't forget to release it in dealloc.

Dennis Munsie
`myArray` must declared as an instance variable. If you don't know how to do that, read this: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html
bbum