0

現在、ほとんどがフォームで構成されているアプリをコーディングしています。仕事をするために、UITextFieldとUITextViewを含むことができるUITableViewControllerで静的セルを使用しています。言語のデフォルト構成を使用している場合、すべてが適切に機能します。しかし、UITextView の場合、リターン キーをタップすると次の行にジャンプするため、キーボードを非表示にできないという弱点があります。そこで、キーボードを閉じる機能を有効にするツールバーを配置しました (キーボードに NSNotification を使用)。ただし、テキストフィールドを含むセルにスクロールすると、フィールドはツールバーによって非表示になり、スクロールによってツールバーの高さが追加されません。スクリーンショット : フィールドをクリックする前 https://dl.dropbox.com/u/9858108/tableViewIssue1.jpg フィールド https://dl.dropbox をクリックした後。

誰もがトリックを行うための魔法のコードスニペットを持っていますか?

4

1 に答える 1

1

A. ヒントをありがとうございます。コードを修正したところ、動作するようになりました。作業コードは次のとおりです。

/**
 * Cette méthode affiche la toolbar pour terminer l'adition quand le clavier est affiché
 *
 * @param NSNotification notification Notification de l'émetteur
 */
- (void)keyboardWillShow:(NSNotification *)notification {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];

    CGRect frame = self.toolbarAction.frame;
    frame.origin.y = self.parentViewController.view.frame.size.height - 260.0;
    self.toolbarAction.frame = frame;

    // Cette portion de code permet de remonter le scroll (à cause de la toolbar)
    if (![[AppKit sharedInstance] isIPad]) {
        CGRect tableFrame = self.tableView.frame;
        tableFrame.origin.y = tableFrame.origin.y - 50;
        self.tableView.frame = tableFrame;
    }

    [UIView commitAnimations];

    // Action pour les keyboards
    self.toolbarDoneButton.tag = 1;
}

/**
 * Cette méthode cache la toolbar lorsque le clavier n'est plus affiché
 *
 * @param NSNotification notification Notification de l'émetteur
 */
- (void)keyboardWillHide:(NSNotification *)notification {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];

    CGRect frame = self.toolbarAction.frame; 
    frame.origin.y = self.parentViewController.view.frame.size.height;
    self.toolbarAction.frame = frame;

    // Cette portion de code permet de rebaisser le scroll (à cause de la toolbar)
    if (![[AppKit sharedInstance] isIPad]) {
        CGRect tableFrame = self.tableView.frame;
        tableFrame.origin.y = tableFrame.origin.y + 50;
        self.tableView.frame = tableFrame;
    }

    [UIView commitAnimations];
}

問題を修正する興味深い部分は次のとおりです。

CGRect tableFrame = self.tableView.frame;
tableFrame.origin.y = tableFrame.origin.y - 50;
self.tableView.frame = tableFrame;
于 2012-07-17T07:51:43.603 に答える