У меня есть метод, привязанный к четырем кнопкам. Я хочу создать массив, содержащий каждую кнопку, а затем извлечь и взаимодействовать с кнопкой из массива. Код, с которым я возился ниже. Когда я пытаюсь получить кнопку из массива и отправить ей сообщение, он выходит kablooie.
Есть мысли о том, что я делаю не так?
Hack_DumpViewController.h
#import <UIKit/UIKit.h>
@interface Hack_DumpViewController : UIViewController {
IBOutlet UIButton *redButton;
IBOutlet UIButton *greenButton;
IBOutlet UIButton *blueButton;
IBOutlet UIButton *yellowButton;
NSArray *buttonMapping;
}
- (IBAction) changeToYo:(id)sender;
@property (nonatomic, retain) UIButton *redButton;
@property (nonatomic, retain) UIButton *greenButton;
@property (nonatomic, retain) UIButton *blueButton;
@property (nonatomic, retain) UIButton *yellowButton;
@property (nonatomic, retain) NSArray *buttonMapping;
@end
Hack_DumpViewController.m
#import "Hack_DumpViewController.h"
@implementation Hack_DumpViewController
@synthesize redButton;
@synthesize greenButton;
@synthesize yellowButton;
@synthesize blueButton;
@synthesize buttonMapping;
- (IBAction) changeToYo:(id)sender {
NSLog(@"changing numbers!");
for (UIButton *b in buttonMapping) {
[b setTitle:@"yo!"];
}
NSLog(@"changed to numbers!");
}
- (void)viewDidLoad {
buttonMapping = [[NSArray alloc] initWithObjects:greenButton, redButton, yellowButton, blueButton, nil];
}