How to activate next UITextField in a UITableView?

前端 未结 4 2071
逝去的感伤
逝去的感伤 2020-12-24 15:05

I am using this other SO answer for adding UITextFields to my UITableViewCells. However, I am now at a loss how I can let the user focus on the nex

4条回答
  •  臣服心动
    2020-12-24 15:57

    Would do you like ..

    NSArray *arrayCells = [self.aTableView visibleCells];
    
    UITableViewCell * currentCell = (UITableViewCell *) textField.superview.superview;
    NSIndexPath * currentIndexPath = [self.aTableView indexPathForCell:currentCell];
    
    if ((currentIndexPath.row != [arrayCells count] - 1) && (currentIndexPath.row < [arrayCells count]-1)) {
    
        NSIndexPath * nextIndexPath = [NSIndexPath indexPathForRow:currentIndexPath.row + 1 inSection:0];
        UITableViewCell * nextCell = (UITableViewCell *) [self.aTableView cellForRowAtIndexPath:nextIndexPath];
    
        [self.aTableView scrollToRowAtIndexPath:nextIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
    
        for (id object in nextCell.contentView.subviews) {
            if ([object isKindOfClass:[UITextField class]]) {
                UITextField *tf = object;
                [tf becomeFirstResponder];
            }
        }
    

提交回复
热议问题