views:

93

answers:

1

I've made a bunch of UIButtons in a grid and I want to be able to iterate over them easily so I've put them in an NSMutableArray.

Like so:

// in .h

UIButton* button1; UIButton* button2; ... UIButton* button9;

UIButton* myButtons[3][3];

// in init function in app

myButtons[0][0] = button1; myButtons[0][1] = button2; ... myButtons[2][2] = button9;

But now if I try to access the title of a button in myButtons I get nil:

// elsewhere in app [button1 setTitle:@"A" forState:UIControlStateNormal];

// and then: NSLog(@"currentTitle of button1: %@", (myButtons[0][0]).currentTitle); // -> (null)

Anybody know what's going on? Thanks!

+1  A: 

first of all, that's not an NSMutableArray, it's just a plain ol' array.

Second, where do you set button1 to a non-null value? Is it before or after assigning myButtons[0][0] = button1;? I would check and make sure that myButtons[0][0] is non-null when calling the NSLog method. If it is, then you need to assign your array later or assign the buttons earlier.

Ed Marty