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?
[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.
精彩评论