我不知道如何在 IBAction 中创建 if-else 语句!我只能在按钮点击中制作它们......我想要它做的是检查 int 问题所在的 # 并进行适当的更改。请帮忙!
主视图.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface MainView : UIView{
IBOutlet UIImageView *background;
IBOutlet UIButton *button1;
IBOutlet UIButton *button2;
IBOutlet UIButton *button3;
IBOutlet UIButton *button4;
IBOutlet UILabel *questionLabel;
}
@property (nonatomic, retain) UIButton *button1;
@property (nonatomic, retain) UIButton *button2;
@property (nonatomic, retain) UIButton *button3;
@property (nonatomic, retain) UIButton *button4;
@property (nonatomic, retain) UILabel *questionLabel;
@property (nonatomic, retain) UIImageView *background;
- (IBAction)Button1clicked;
- (IBAction)Button2clicked;
- (IBAction)Button3clicked;
- (IBAction)Button4clicked;
@end
主视图.m
#import "MainView.h"
@implementation MainView
@synthesize button1, button2, button3, button4, questionLabel, background;
int question = 1;
BOOL oneRight = FALSE;
BOOL twoRight = FALSE;
BOOL threeRight = FALSE;
BOOL fourRight = FALSE;
- (IBAction)Button1clicked {
if (oneRight == TRUE) {
questionLabel.text = @"CORRECT!";
question++;
} else {
questionLabel.text = @"FAIL";
}
}
- (IBAction)Button2clicked {
if (twoRight == TRUE) {
questionLabel.text = @"CORRECT!";
question++;
} else {
questionLabel.text = @"FAIL";
}
}
- (IBAction)Button3clicked {
if (threeRight == TRUE) {
questionLabel.text = @"CORRECT!";
question++;
} else {
questionLabel.text = @"FAIL";
}
}
- (IBAction)Button4clicked {
if (fourRight == TRUE) {
questionLabel.text = @"CORRECT!";
question++;
} else {
questionLabel.text = @"FAIL";
}
}
int foo(int question) {
if (question == 1) {
oneRight = TRUE;
twoRight = FALSE;
threeRight = FALSE;
fourRight = FALSE;
}
}
@end