nick130586
nick130586

Reputation: 841

accessing Objective-C nested array element

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?

Upvotes: 0

Views: 1594

Answers (1)

Dennis Munsie
Dennis Munsie

Reputation: 1211

[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.

Upvotes: 3

Related Questions