グループ化された静的テーブルビューを使用して、iPhoneアプリに入力フォームを実装しようとしています。
私はdidSelectRowAtIndexPath
怠惰にテキストフィールドを作成し、関連するセルに追加するために使用しています。
私の問題は、それbecomeFirstResponder
が期待どおりに動作していないことです。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section == 0)
{
if(!self.contactNameTextField)
{
self.contactNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(93, 14, 200, 20)];
self.contactNameTextField.backgroundColor = [UIColor clearColor];
self.contactNameTextField.font = [UIFont boldSystemFontOfSize:15];
self.contactNameTextField.keyboardType = UIKeyboardTypeEmailAddress;
[self.contactNameCell addSubview:self.contactNameTextField];
}
[self.contactNameTextField becomeFirstResponder];
}
if(indexPath.section == 1)
{
if(!self.contactEmailTextField)
{
self.contactEmailTextField = [[UITextField alloc] initWithFrame:CGRectMake(93, 14, 200, 20)];
self.contactEmailTextField.backgroundColor = [UIColor clearColor];
self.contactEmailTextField.font = [UIFont boldSystemFontOfSize:15];
self.contactEmailTextField.keyboardType = UIKeyboardTypeEmailAddress;
[self.contactEmailCell addSubview:self.contactNameTextField];
}
[self.contactEmailTextField becomeFirstResponder];
}
コードは期待どおりにステップスルーします。
最初にセクション0をタップすると、名前のテキストフィールドがファーストレスポンダーになります。次にセクション1をタップすると、メールのテキストフィールドがファーストレスポンダーになります。次にセクション0をタップするbecomeFirstResponder
と、名前のテキストフィールドで呼び出されても、応答しません。
また、最初にセクション1をタップするbecomeFirstResponder
と、メールのテキストフィールドで呼び出されても応答しません。
お知らせ下さい