私は1 つのビュー コントローラーに 5 つの UITextFieldsがあるアプリに取り組んでいます。ユーザーは必要なテキスト フィールドに入力でき、 UIButtonを押すと、UILabel を介して 2 番目のビュー コントローラーでランダムな回答が得られます。
これまでのところ動作するようになりましたが、ユーザーが最初の 2 つの UITextFields のみを入力し、ランダムな回答が空白の未入力の UITextFieldからのものであるとしましょう。
私の質問は: 埋められていない UITextFieldsがランダム カウントの一部にならないようにするにはどうすればよいですか? これは可能ですか?
コードは次のとおりです。
FifthViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.choice1.delegate = self;
self.choice2.delegate = self;
self.choice3.delegate = self;
self.choice4.delegate = self;
self.choice5.delegate = self;
}
- (IBAction)choicebutton:(id)sender {
SixthViewController *SVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SixthViewController"];
SVC.stringFromChoice1 = self.choice1.text;
SVC.stringFromChoice2 = self.choice2.text;
SVC.stringFromChoice3 = self.choice3.text;
SVC.stringFromChoice4 = self.choice4.text;
SVC.stringFromChoice5 = self.choice5.text;
[self presentViewController:SVC animated:YES completion:nil];
}
SixthViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.choiceAnswers = @[self.stringFromChoice1,
self.stringFromChoice2,
self.stringFromChoice3,
self.stringFromChoice4,
self.stringFromChoice5];
int index = arc4random() % [self.choiceAnswers count];
self.choiceanswer.text = self.choiceAnswers[index];
}
ありがとう!