フィールドにテキストを入力したときに呼び出されるIBActionがあります。次に、入力を検証します。エラーがあると判断した場合は、メッセージを表示して、同じフィールドに再度入力する必要があります。キーボードを持ち上げるためにテキストフィールドを選択させるのではなく、キーボードを表示させたままにします。キーボードを強制的に表示したままにすることはできますか?
私はIBActionの最後のステートメントとして[SymbolEntered becomeFirstResponder];
を行っていますが、キーボードはまだ消えています。私はそれを間違った場所に置いていますか?どんな助けもありがとう。ありがとう。
- (IBAction)textFieldDoneEditing:(id)sender {
DebugMsg.text = nil;
DebugMsg2.text = nil;
DebugMsg3.text = nil;
NSLog (@"done editing");
NSLog (@"%@", SymbolEntered.text);
if ([SymbolEntered.text isEqualToString:nil])
{
Result.textColor = [UIColor redColor];
Result.text = @"You must enter a symbol!";
[SymbolEntered becomeFirstResponder];
}
else
{
if ([SymbolEntered.text isEqualToString:
[NSString stringWithCString:elements_table2[el_tbl_idx-1].element_symbol]])
{
correct_count++;
Result.textColor = [UIColor greenColor];
Result.text = @"Correct!";
Score.hidden = FALSE;
Score.text = [NSString stringWithFormat:@"Score: %d out of %d - %d Percent", correct_count, el_count+1,
(correct_count*100)/(el_count+1)];
GetNextElementButton.hidden = FALSE;
SymbolEntered.enabled = FALSE;
el_count++;
attempts = max_tries + 1;
}
else
{
Score.hidden = TRUE;
Result.textColor = [UIColor redColor];
if (attempts < max_tries)
{
if (attempts+1 == max_tries)
{
Result.text = @"Sorry, one more try -";
}
else
{
Result.text = @"Sorry, try again - ";
}
GetNextElementButton.hidden = TRUE;
attempts++;
}
else
{
Result.text = [[NSString alloc] initWithFormat: @"Sorry. The correct answer is %@",
[NSString stringWithCString:elements_table2[el_tbl_idx-1].element_symbol]];
Score.hidden = FALSE;
Score.text = [NSString stringWithFormat:@"Score: %d out of %d - %d Percent", correct_count, el_count+1, (correct_count*100)/(el_count+1)];
GetNextElementButton.hidden = FALSE;
SymbolEntered.enabled = FALSE;
el_count++;
}
}
}
[SymbolEntered becomeFirstResponder];
NSLog (@"end of textfieldoneediting");
}
ソースコードのどこでも 'resignFirstResponder'が呼び出されていますか? – Espresso
このIBActionではなく、キーボードが表示されているときにバックグラウンドタップのIBActionで呼び出されます。 – Rick