iPhone:在uitableview中跳转到下一个uitextfield,怎么样? [英] iPhone: Jump to next uitextfield in uitableview, how to?

查看:94
本文介绍了iPhone:在uitableview中跳转到下一个uitextfield,怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iPhone项目中,我正在使用包含UITextfields的UITableViewCells的UITableview。我在许多应用程序中看到,可以使用下一个按钮跳转到下一个单元格中的下一个文本字段。完成此任务的最佳方法是什么?

In my iPhone project I'm using a UITableview with UITableViewCells containing UITextfields. I have seen in many apps that it is possible to use a next button to jump to the next textfield in the next cell. What is the best way to accomplish this?

我的想法是获取正在编辑的文本字段的单元格的indexPath,然后通过cellForRowAtIndexPath获取下一个单元格。但是如何获取我正在编辑的单元格的indexPath?

My idea is to get the indexPath of the cell with the textfield that is being editing and then get the next cell by cellForRowAtIndexPath. But how can I get the indexPath of the cell I'm currently editing?

谢谢!

推荐答案


  1. 在表格视图中保持对 UITextField 实例的引用。

  2. 将唯一标记值分配给 UITextField 个实例。

  3. 在上一个文本字段中,您可以设置其Return键类型,它将键盘的Return键标签从Next更改为Done: [finalTextField setReturnKeyType:UIReturnKeyDone];

  1. Keep references to the UITextField instances in your table view.
  2. Assign unique tag values to your UITextField instances.
  3. In your last text field, you might set its Return key type, which changes the keyboard's Return key label from "Next" to "Done": [finalTextField setReturnKeyType:UIReturnKeyDone];

UITextField 委托方法 -textFieldShouldReturn:,遍历响应者:

In the UITextField delegate method -textFieldShouldReturn:, walk through the responders:

- (BOOL) textFieldShouldReturn:(UITextField *)tf {
    switch (tf.tag) {
        case firstTextFieldTag:
            [secondTextField becomeFirstResponder];
            break;
        case secondTextFieldTag:
            [thirdTextField becomeFirstResponder];
            break;
        // etc.
        default:
            [tf resignFirstResponder];
            break;
    }
    return YES;
}

这篇关于iPhone:在uitableview中跳转到下一个uitextfield,怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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