移至表格单元格中的下一个文本字段 [英] To move to next text fieds in table cell

查看:69
本文介绍了移至表格单元格中的下一个文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,有一个表格视图,每个单元格有2个文本字段.我正在为每个文本字段分配标签.在按下完成按钮时,我要使下一个文本字段成为第一个响应者(可以在表格单元格之间).但是我现在使用的代码不起作用.附加当前代码

In my application , there is a table view with 2 text fields per cell. Am assigning tags for each text field. On pressing done button i want to make the next text field the first responder(can be between table cells). But the code now i am using does not work . attaching the present code

    NSArray *viewsToBecomeFirstResponder = [tableView subviews];
for (UIView *firstResponder in viewsToBecomeFirstResponder) {
    if ([firstResponder isKindOfClass:[UITextField class]]) {
        if (firstResponder.tag == nextTag ) {
            [firstResponder becomeFirstResponder];

        }

    }

}

我没有在子视图数组中获得文本字段.我正在为表格单元格使用自定义单元格.请帮忙.

I am not getting the text fields in the sub view array. I am using custom cell for table cells. Please help.

推荐答案

只需对Karim的代码进行少量修改,就可以访问如下textVies:

With little modification to Karim's code you can access the textVies like this:

- (void)textViewDidEndEditing:(UITextView *)textView {
   //Get the indexPath for the currently selected cell
   NSIndexPath *cellPath = [(UITableView*)[self view] indexPathForSelectedRow];

   //Get the actual cell
   CustomTableCell *cell = (CustomTableCell *)[(UITableView*)[self view] cellForRowAtIndexPath:cellPath];

   int currentTag = textView.tag;
   int nextTag = currentTag + 1; // or something else

   UITextView *nextTV = [cell viewWithTag: nextTag];
   [nextTV becomesFirstResponder];
}

希望这会有所帮助.

这篇关于移至表格单元格中的下一个文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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