Ios 使用各种控件(按钮、开关和文本字段)在tableview中实现上一个/下一个按钮

Ios 使用各种控件(按钮、开关和文本字段)在tableview中实现上一个/下一个按钮,ios,uitableview,uitextfield,Ios,Uitableview,Uitextfield,我有一个场景,我必须在tableview中实现上一个/下一个按钮。该表由自定义单元格组成。其中一些是下拉列表、一些开关和一些文本字段。它由多个部分和行组成 单击“下一步”按钮,我需要从一个文本字段跳到下一个文本字段 我可以将我的问题陈述分为: 1.当按下文本字段上的“下一步”按钮时,在表格中查找下一个连续的文本字段。 2.滚动到下一个字段。 3.让它成为第一反应者 我已经尝试了很多在线可用的技术,但运气不佳。此外,任何其他建议都将有助于如何继续实现此类功能 NSMutab

我有一个场景,我必须在tableview中实现上一个/下一个按钮。该表由自定义单元格组成。其中一些是下拉列表、一些开关和一些文本字段。它由多个部分和行组成

单击“下一步”按钮,我需要从一个文本字段跳到下一个文本字段

我可以将我的问题陈述分为: 1.当按下文本字段上的“下一步”按钮时,在表格中查找下一个连续的文本字段。 2.滚动到下一个字段。 3.让它成为第一反应者

我已经尝试了很多在线可用的技术,但运气不佳。此外,任何其他建议都将有助于如何继续实现此类功能

            NSMutableArray *cells = [[NSMutableArray alloc] initWithArray:[tableView visibleCells]];
            int count1 = 0;
           //tableViewCell_Ncolumn is a custome cell
            for (tableViewCell_Ncolumn *cell in cells)
            {
                count1 ++;
                 for (UIView *view in  cell.contentView.subviews)
                 {
                     if ([view isKindOfClass:[UITextField class]])
                     {

                           UITextField* currField = (UITextField *)view;
                            for (int i=count1; i<[cells count]; i++)
                            {
                                UITextField *nextField;
                                 //Geting current textfield and checking if it is being edited
                                 if ([currField isEditing])
                                      {
                                          tableViewCell_Ncolumn *nextCell = [cells objectAtIndex:i+1];
                                          for (UIView *view in  cell.contentView.subviews)
                                          {
                                              if ([view isKindOfClass:[UITextField class]])
                                              {
                                                  nextField = (UITextField *)view;
                                              }
                                              else
                                              {
                                                  //loop till you find next textfield in the table

                                              }
                                          }


                                          [nextField becomeFirstResponder];

                                          [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:i+1 inSection:1] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];

                                          break;


                                      }

                            }

                     }
                 }
            }
        };
NSMutableArray*cells=[[NSMutableArray alloc]initWithArray:[tableView visibleCells]];
int count1=0;
//tableViewCell\u Ncolumn是一个自定义单元格
用于(tableViewCell\u Ncolumn*单元格中的单元格)
{
count1++;
for(UIView*cell.contentView.subview中的视图)
{
if([view iskindof类:[UITextField类]])
{
UITextField*currField=(UITextField*)视图;

对于(int i=count1;i最好的方法是使用give标记属性

 UITextField* currField=[cell.contentView viewWithTag:5];
 UITextField* nextField =[cell.contentView viewWithTag:6];

     [currField resignFirstResponder];
     [nextField becomeFirstResponder];

对于文本字段,您可以使用下面的方法,其他控件的变通方法可以通过此方法开发


文本字段应开始编辑-设置滚动位置
操作下一步-将第一响应者设置为下一个文本字段
actionPrevious-将第一响应者设置为prev text当前
行动完成-辞职第一响应者

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

    if (textField.tag == 25)
    {

        [tableView setContentOffset:CGPointMake(0,theCell.center.y-65) animated:YES];

      // or you can use this method as well      
      // [[self tableView] scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

   return YES;

    }
 }

- (IBAction)actionPrevious:(id)sender {

    if ([self.textFieldEmployer1 isFirstResponder])
    {
       [self.textFieldConfirmPassword becomeFirstResponder];
    }
    else if ([self.textFieldConfirmPassword isFirstResponder])
    {
       [self.textFieldPassword becomeFirstResponder];
    }

 }

  - (IBAction)actionNext:(id)sender {

    if ([self.textFieldEmail isFirstResponder])
    {
        [self.textFieldPassword becomeFirstResponder];
    }
   else if ([self.textFieldUserName isFirstResponder])
   {
       [self.textFieldPassword becomeFirstResponder];
   }

}

- (IBAction)actionDone:(id)sender
{

[self.view endEditing:YES];

}

我遇到了类似的问题,最终创建了
UIToolbar
的子类来管理下一个/上一个功能:

您可以将工具栏设置为文本字段的
inputAccessoryView
,并将其添加到其字典中。这样,您就可以前后循环查看这些字段,即使是动态内容。有一个示例应用程序可帮助您了解实现细节。您需要自己的数据模型来跟踪字段中的值

DataEntryToolbar
是用swift编写的,但你可以将其与objective-c代码混合使用,没有问题。如果你在这方面遇到任何问题,请在
将swift导入objective-c
下查看苹果的文档:

编辑:
刚刚意识到这篇文章已经快一年了,但希望这能帮助其他人。

谢谢你的回复。但我必须在多个动态的TableView上实现这一点。文本字段可能会出现,也可能不会出现,这取决于下拉列表和其他选择。继续使用此解决方案是否更好?如果是动态的然后你应该在数组中添加textfield,并得到相应的textfield。上面你所做的事情很奇怪,也不标准