I've 16 buttons in a view named as:
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb1;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb2;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb3;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb4;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb5;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb6;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb7;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb8;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb9;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb10;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb11;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb12;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb13;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb14;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb15;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *bb16;
I want to set the background of image based on different conditions in a switch statement. So what I'm doing is that I've a for loop
for (int i=1; i<=16; i++) {
int val = [(NSNumber *)[self.valuesArray objectAtIndex:i] intValue];
NSString *newString = [NSString stringWithFormat:@"bb%d",i];
switch (val) {
case 4:
[**self.bb%d** setBackgroundImageNamed:@"s"];
break;
default:
break;
}
}
The val
is the value it is currently picking from an NSArray
and below that is a newString
which is creating the required strings. The text inside **
is something I'm stuck at of-course I put the **
my self to highlight the problem. I want to change background image of the buttons based on different cases. So if it's case 4
than change it to s
and if it's 0
change it to something else. So how can I achieve it. I hope my question is clear.