我有一個IBAction,當有人在字段中輸入文本時被調用。然後我驗證輸入。如果我確定有錯誤,我會顯示一條消息,並希望用戶再次進入同一字段。而不是讓他們選擇文本字段來使鍵盤(這工作正常),我想只留下鍵盤顯示。如何強制鍵盤保持顯示?
我在做[SymbolEntered becomeFirstResponder];
作爲我的IBAction中的最後一個聲明,但鍵盤仍然消失。我把它放在錯誤的地方?任何幫助,將不勝感激。謝謝。
- (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 2012-04-25 00:07:29
不在此IBAction中,但在顯示鍵盤時,它在IBAction中被調用以獲得背景抽頭。 – Rick 2012-04-25 00:46:12