Quote:
Originally Posted by baja_yu
With the my code above do
Code:
columnNumber = 1;
rowNumber = 1;
theButtonToUse = (UIButton *)[(NSMutableArray *)[buttonArray objectAtIndex:rowNumber] objectAtIndex:columnNumber]
//then do what you want to theButtonToUse
EDIT: Also, just note that NSMutableArrays are zero based so your button indexes (column/row numbers) would go from 0 to 4 instead of 1 to 5.
|
Thanks again Baja_Yu. After a bit of testing I came to realise the issue with the 0 and changed them accordingly. However, it still isn't working.
In this example I have 3 columns and two rows.
.h has the following:
#import <UIKit/UIKit.h>
@interface Button_TestViewController : UIViewController {
IBOutlet UIButton * Button1;
IBOutlet UIButton * Button2;
IBOutlet UIButton * C0R0;
IBOutlet UIButton * C1R0;
IBOutlet UIButton * C2R0;
IBOutlet UIButton * C0R1;
IBOutlet UIButton * C1R1;
IBOutlet UIButton * C2R1;
IBOutlet UIButton * TellMeImage;
NSString * ItemISelected;
UIButton * MyButtonToCheck;
}
-(IBAction) ButtonPushed

id)sender;
-(IBAction) ItemSelected

id)sender;
-(IBAction) MessageMeImage;
@end
This is my function in .m
-(IBAction) MessageMeImage{
NSMutableArray *buttonArray = [[NSMutableArray alloc] init];
for (int i=0; i<2; i++) {
NSMutableArray *insideArray = [[NSMutableArray alloc] init];
for (int j=0; j<3; j++) {
UIButton *aButton = [[UIButton alloc] init];
[aButton setTitle:[NSString stringWithFormat:@"C%dR%d", j, i] forState:UIControlStateNormal];
NSLog([NSString stringWithFormat:@"C%dR%d", j, i]);
[insideArray addObject:aButton];
[aButton release];
}
[buttonArray addObject:insideArray];
[insideArray release];
}
MyButtonToCheck = (UIButton *)[(NSMutableArray *)[buttonArray objectAtIndex:1] objectAtIndex:1];
NSLog([NSString stringWithFormat:@"%d", C1R1]);
NSLog([NSString stringWithFormat:@"%d", MyButtonToCheck]);
[MyButtonToCheck setImage:[UIImage imageNamed:@"two.PNG"] forState:UIControlStateNormal];
}
NSLog comes out as follows:
2010-11-24 00:36:38.756 Button Test[1418:207] C0R0
2010-11-24 00:36:38.758 Button Test[1418:207] C1R0
2010-11-24 00:36:38.759 Button Test[1418:207] C2R0
2010-11-24 00:36:38.760 Button Test[1418:207] C0R1
2010-11-24 00:36:38.761 Button Test[1418:207] C1R1
2010-11-24 00:36:38.763 Button Test[1418:207] C2R1
2010-11-24 00:36:38.764 Button Test[1418:207] 99990976
2010-11-24 00:36:38.767 Button Test[1418:207] 100063968
2010-11-24 00:36:38.996 Button Test[1418:207] C0R0
2010-11-24 00:36:38.998 Button Test[1418:207] C1R0
2010-11-24 00:36:38.999 Button Test[1418:207] C2R0
2010-11-24 00:36:39.000 Button Test[1418:207] C0R1
2010-11-24 00:36:39.002 Button Test[1418:207] C1R1
2010-11-24 00:36:39.003 Button Test[1418:207] C2R1
2010-11-24 00:36:39.004 Button Test[1418:207] 99990976
2010-11-24 00:36:39.007 Button Test[1418:207] 100066704
2010-11-24 00:36:39.197 Button Test[1418:207] C0R0
2010-11-24 00:36:39.198 Button Test[1418:207] C1R0
2010-11-24 00:36:39.199 Button Test[1418:207] C2R0
2010-11-24 00:36:39.201 Button Test[1418:207] C0R1
2010-11-24 00:36:39.202 Button Test[1418:207] C1R1
2010-11-24 00:36:39.203 Button Test[1418:207] C2R1
2010-11-24 00:36:39.204 Button Test[1418:207] 99990976
2010-11-24 00:36:39.207 Button Test[1418:207] 100069392
2010-11-24 00:36:39.433 Button Test[1418:207] C0R0
2010-11-24 00:36:39.435 Button Test[1418:207] C1R0
2010-11-24 00:36:39.436 Button Test[1418:207] C2R0
2010-11-24 00:36:39.437 Button Test[1418:207] C0R1
2010-11-24 00:36:39.439 Button Test[1418:207] C1R1
2010-11-24 00:36:39.440 Button Test[1418:207] C2R1
2010-11-24 00:36:39.442 Button Test[1418:207] 99990976
2010-11-24 00:36:39.443 Button Test[1418:207] 100072128
2010-11-24 00:36:43.210 Button Test[1418:207] C0R0
2010-11-24 00:36:43.212 Button Test[1418:207] C1R0
2010-11-24 00:36:43.213 Button Test[1418:207] C2R0
2010-11-24 00:36:43.214 Button Test[1418:207] C0R1
2010-11-24 00:36:43.215 Button Test[1418:207] C1R1
2010-11-24 00:36:43.216 Button Test[1418:207] C2R1
2010-11-24 00:36:43.217 Button Test[1418:207] 99990976
2010-11-24 00:36:43.220 Button Test[1418:207] 100074864
It seems as though the permanent name (C1R1) returns the same value every time but the function we're trying to create just goes up and up??
Needless to say, the image doesn't change as it should. Any ideas? Thank you so much for you time!