1

私はこれで立ち往生しています.この問題を整理するのを手伝ってください. これは私のイメージです。テーブルには5つの異なる行があります。最初のフィールドを編集した後に最初のテキストフィールドをクリックすると、ボタンをクリックして2番目のフィールドに移動し、テキストビューとテキストフィールドを同時に開きます(画像に示すように)。カテゴリフィールドにはピッカー ビュー、名前フィールド (画像に表示)、場所には画像と同じ、価格にはアクション シートがあります。

今、価格フィールドのアクションシートのコードを追加しました.誰かが私が必要なものを達成するのを手伝ってくれますか.

ここに画像の説明を入力

私はこのようなことをしていますが、まだうまくいきません。コードは次のとおりです。

- (void) textFieldDoneTouched
{

    [self.site setValue:textField.text forIndex:selectedRow];

    [UIView animateWithDuration:0.3
                     animations:^{
                         CGRect f = textFieldContainerView.frame;
                         f.origin.y = self.view.frame.size.height;
                         textFieldContainerView.frame = f;
                     }];

    [textField resignFirstResponder];
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:selectedRow inSection:0];
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    self.tableView.userInteractionEnabled = YES;

    [self.view endEditing:TRUE];

    [self validateSiteData];
}

- (BOOL) textFieldShouldReturn:(UITextField *)textField
{

        [self textFieldDoneTouched];
    return YES;
}

#pragma mark -
#pragma mark UITextViewDelegate

- (void) textViewDoneTouched
{




    [self.site setValue:textView.text forIndex:selectedRow];

    [UIView animateWithDuration:0.3
                     animations:^{
                         CGRect f = textViewContainerView.frame;
                         f.origin.y = self.view.frame.size.height;
                         textViewContainerView.frame = f;
                     }];

    [textView resignFirstResponder];
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:selectedRow inSection:0];
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    self.tableView.userInteractionEnabled = YES;

    [self validateSiteData];
}


#pragma mark - UIActionSheetDelegate

- (void) actionSheet:(UIActionSheet *)actionSheet1 clickedButtonAtIndex:(NSInteger)buttonIndex
{

    if(buttonIndex == 0) {
        self.site.price = @"Free";
       // NSIndexPath *indexPath = [NSIndexPath indexPathForItem:4 inSection:0];

       // [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:100];
        //[textField resignFirstResponder];
       // [textView becomeFirstResponder];
        }
    else if(buttonIndex == 1) {
        self.site.price = @"Paid ($)";
       // NSIndexPath *indexPath = [NSIndexPath indexPathForItem:4 inSection:0];

      //  [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:100];
       // [textField resignFirstResponder];
         //[textView becomeFirstResponder];
        }


    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:selectedRow inSection:0];
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

    [self validateSiteData];

}
4

1 に答える 1

1

では、コンピュータのキーボードで Tab キーを押すように、iPhone のリターン キーで次のフィールドに移動したいと思いませんか?

ちょっとした注意: スクリーンショットの青い「完了」キーではなく、デフォルトのグレーの「リターン」キーを使用することをお勧めします。「完了」は、ユーザーがフォームへの入力を完了し、キーボードが非表示になったときを示します。「戻る」は、Apple の連絡先アプリのように、次のフィールドまたはテキスト行に移動するためのものです。

アップルの連絡先

Apple の連絡先アプリと同様に、UITextFields をラベル (Category、Name...) と同じ UITableViewCells に配置することもお勧めします。スクリーンショットのキーボードの真上にあるテキスト フィールドが少しわかりにくいと思います。これを行うと、次の の実装によりtextFieldShouldReturn、次のセルのテキスト フィールドがファーストレスポンダになります。

- (BOOL) textFieldShouldReturn:(UITextField*)textField {
    // Determine the row number of the active UITextField in which "return" was just pressed.
    id cellContainingFirstResponder = textField.superview.superview ;
    NSInteger rowOfCellContainingFirstResponder = [self.tableView indexPathForCell:cellContainingFirstResponder].row ;
    // Get a reference to the next cell.
    NSIndexPath* indexPathOfNextCell = [NSIndexPath indexPathForRow:rowOfCellContainingFirstResponder+1 inSection:0] ;
    TableViewCell* nextCell = (TableViewCell*)[self.tableView cellForRowAtIndexPath:indexPathOfNextCell] ;
    if ( nextCell )
        [nextCell.theTextField becomeFirstResponder] ;
    else
        [textField resignFirstResponder] ;
    return YES ;
}

プロジェクト全体を投稿したい場合はお知らせください。

UITableViewCells 内の UITextFields

于 2013-01-29T17:11:44.347 に答える