1

我被困在这个问题上。请帮助我解决这个问题。这是我的图像,现在我在表中有 5 个不同的行。如果您在编辑第一个字段后单击第一个文本字段,那么我想要完成按钮单击转到第二个字段并同时打开文本视图和文本字段(如图所示)。归档的类别具有选择器视图,名称字段(如图所示),位置与图像相同,价格具有操作表。

现在我已经为价格字段的操作表添加了代码。有人可以帮我实现要求吗。谢谢你的帮助...... :)

在此处输入图像描述

我正在做这样的事情,但它还没有为我工作。代码是:

- (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

那么,您希望 iPhone 的返回键转到下一个字段,就像在计算机键盘上按 Tab 键一样?

一个小提示:我建议使用默认的灰色“返回”键,而不是屏幕截图中的蓝色“完成”键。“完成”是指用户填写完表格并且键盘应该消失的时候;“return”用于转到下一个字段或文本行,就像在 Apple 的联系人应用程序中一样。

苹果通讯录

与 Apple 的联系人应用程序一样,我还建议您的 UITextField 与其标签(类别、名称...)位于相同的 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 回答