質問

セルのコンテンツビューに追加された 3 つの UITextFields を持つテーブルがあります (セクションごとに 1 行)。特定のフィールドをスクロールしてキーボードの上に表示できるように、4 番目のセクションを挿入します。

私が抱えている問題(iPadのみ)は、テキストフィールドの1つにfirstResponderがある場合、ユーザーが別のフィールドをタップしてもそれを放棄しないことです。iPad のレスポンダー チェーンに違いはありますか?私のビューコントローラーの以下のコードでは、UITextFieldDelegate - textFieldShouldEndEditing は、別のフィールドに触れても呼び出されません。[完了] ボタンを押すと、(別のフィールドがタッチされていない限り) 期待どおりに機能します。

以下のコードに何か問題がありますか?

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (!_editing++) {
        [self.tableView insertSections:[NSIndexSet indexSetWithIndex:4] withRowAnimation:UITableViewRowAnimationNone];
    }

    // scroll to section number in the text fields tag
    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:textField.tag] atScrollPosition:UITableViewScrollPositionTop animated:YES];

    return YES;
}

- (void) textFieldDidBeginEditing:(UITextField *)textField {
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:textField action:@selector(resignFirstResponder)] autorelease]; 
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    if (_editing-- == 1) {
        // 
        [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:4] withRowAnimation:UITableViewRowAnimationNone];
    }

    self.navigationItem.rightBarButtonItem = nil;

    // do something with the text here...

    return YES;
}
役に立ちましたか?

解決

OK、満足のいく回避策を見つけました。セクションの削除をアニメーション化するリクエストが問題を解決する前に、実行ループの実行を許可しているようです。これはリンゴのバグなのでしょうか?この問題を心配している他の人のために - 私は iPad で iOS3.2.1 を実行していました。

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    if (_editing == 1) {
        [self performSelector:@selector(hideFinalSection) withObject:nil afterDelay:0.0f];
    }
    else {
        _editing--;
    }

    self.navigationItem.rightBarButtonItem = nil;

        // do something with the text here...

    return YES;
}

- (void) hideFinalSection {
    if (!(--_editing)) { 
        [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:4] withRowAnimation:UITableViewRowAnimationNone];
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top