如何使用textview移动到表格视图中的下一个单元格/行 [英] how to move to next cell/row in table view with textview

查看:25
本文介绍了如何使用textview移动到表格视图中的下一个单元格/行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i am stuck at this .please help me in sorting out this issue. this is my image now i have 5 different rows in the table. if u click on first textfield after editing the first field then i want done button click to goto the second field and open textview and textfield simulatneously(as shown in the image). The Category Filed is having picker view,The Name field (shown in image),Location is having same as image,price is having a action sheet.

现在我已经为价格字段的操作表添加了代码.有人可以帮我实现所需的.感谢您的帮助... :)

Now i have added code for action sheet of Price Field .Can somebody help me achieve the required.Thanks for help... :)

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

i am doing something like this but it is not yet worked for me. the code is:

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

}

推荐答案

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

So, you'd like the iPhone's return key to go to the next field, like pressing Tab on a computer keyboard?

一个小注意事项:我建议使用默认的灰色返回"键,而不是屏幕截图中的蓝色完成"键.完成"是当用户完成填写表单并且键盘应该消失时;返回"用于转到下一个字段或文本行,就像在 Apple 的通讯录应用中一样.

One minor note: I'd recommend using the default grey "return" key, not the blue "Done" key in your screenshot. "Done" is for when the user is done filling out the form and the keyboard should disappear; "return" is for going to the next field or row of text, as in Apple's Contacts app.

与 Apple 的联系人应用程序一样,我还建议您的 UITextFields 与它们的标签(类别、名称...)位于相同的 UITableViewCells 中.我发现屏幕截图中键盘正上方的文本字段有点令人困惑.如果您这样做,那么 textFieldShouldReturn 的以下实现将使下一个单元格的文本字段成为第一响应者.

Like Apple's Contacts app, I'd also recommend that your UITextFields be in the same UITableViewCells as their labels (Category, Name...). I find the text field directly above the keyboard in your screenshot a little confusing. If you do that, then the following implementation of textFieldShouldReturn will make the next cell's text field into the first responder.

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

如果您希望我发布整个项目,请告诉我.

Let me know if you'd like me to post the whole project.

这篇关于如何使用textview移动到表格视图中的下一个单元格/行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆