単語ジェネレーターに「if」ステートメントを追加しようとすると、「Expected Expression」というエラーが表示されます。if ステートメントを取り出すと問題なく動作しますが、いくつかの単語ジェネレーターを用意し、変数「変数」の値に応じて、どの単語ジェネレーターにアクセスするかを決定します。
例: 「変数」が 1 の場合、最初のワード ジェネレータがアクセスされます。「変数が 2 に等しい場合、2 番目のワード ジェネレータがアクセスされます。
以下は私の実装ファイルのコードです。
#import "ViewController2.h"
#import "ViewController.h"
#import "ViewController3.h"
@interface ViewController2 ()
@end
@implementation ViewController2
-(IBAction)random {
if (int variable = 3) {
int text = rand() %3;
switch (text) {
case 0:
introLabel.text = @"Test 1";
break;
case 1:
introLabel.text = @"Test 2";
break;
case 2:
introLabel.text = @"Test 3";
break;
default:
break;
}
}
}
-(IBAction)backButton:(id)sender {
ViewController *viewController2 = [[ViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:viewController2 animated:YES];
}
-(IBAction)moreButton:(id)sender {
ViewController3 *viewController2 = [[ViewController3 alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:viewController2 animated:YES];
}
助けてくれてありがとう。