Navigate through textfields in UITableView swift

get textfield value from uitableviewcell swift
get text from uitextfield in uitableviewcell swift 4
uitableview with textfield example
uitextfield automatically move to next field swift
move to next textfield swift
uitableview form swift
uitableview inside uitableviewcell example swift
how to move cursor from one text field to another automatically in swift ios programmatically?

Trying to navigate through text fields in UITableView. Able to navigate through text fields on simple view but not getting how to navigate when text fields are in UITableView.

Below is the code tried so far:

func textFieldDidBeginEditing(textField: UITextField)
{

    //textField.inputAccessoryView = numberToolbar
    if(textField == txtConfirmPassword)
    {
        textField.returnKeyType = UIReturnKeyType.Done
    }
    else
    {
        textField.returnKeyType = UIReturnKeyType.Next
    }
}

Please guide thanks.

Update:

func textFieldDidBeginEditing(textField: UITextField)
{
    if(delegate != nil)
    {
        delegate?.performSelector(NSSelectorFromString("editingTextField"))
    }

    if(textField.tag == 3)
    {
        textField.returnKeyType = UIReturnKeyType.Done
    }
    else
    {
        textField.returnKeyType = UIReturnKeyType.Next
    }
}

func textFieldShouldReturn(textField: UITextField) -> Bool
{
    if(delegate != nil)
    {
        delegate?.performSelector(NSSelectorFromString("editingDone"))
    }
    if(textField.tag == 3)
    {
        textField.resignFirstResponder()
        delegate?.performSelector(NSSelectorFromString("editingDone"))

    }

     let nextTage=textField.tag+1
    // Try to find next responder
    let nextResponder=textField.superview?.viewWithTag(nextTage) as UIResponder!

    if (nextResponder != nil){
        // Found next responder, so set it.
        nextResponder?.becomeFirstResponder()
    }
    else
    {
        // Not found, so remove keyboard
        textField.resignFirstResponder()
    }
    return true
}

Here is the code for Swift 2.1

Here I have taken SampleTableViewCell which is a custom cell in which i have created textField.

For the purpose I have just taken the tag based on cell, so while accessing it in the textField's delegate method, You can know the textField is for which cell.

Here is the code :

//UITableView Delegate

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
     let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! SampleTableViewCell
    cell.txtFld.delegate = self;
    cell.txtFld.tag = indexPath.row + 100

    cell.selectionStyle = UITableViewCellSelectionStyle.Gray;


    return cell;
}

UPDATE : Here is the delegate for TextField

//UITextField Delegate

func textFieldDidBeginEditing(textField: UITextField)
{

    //textField.inputAccessoryView = numberToolbar
    if(textField.tag == 100)
    {
        textField.returnKeyType = UIReturnKeyType.Done
    }
    else
    {
        textField.returnKeyType = UIReturnKeyType.Next
    }
}

Here I have navigate to next textfield by clicking the return button of text field.

// called when 'return' key pressed. return NO to ignore.
func textFieldShouldReturn(textField: UITextField) -> Bool
{
    textField.resignFirstResponder();

    if(textField.tag == 100)
    {
        let txtFld = self.tblList.viewWithTag(101);
        txtFld?.becomeFirstResponder();
    }

    return true;
}

Hope it helps.

Happy coding ...

Here is the code for Swift 2.1. Here I have taken SampleTableViewCell which is a custom cell in which i have created textField. For the purpose I have just taken  the textfields are dragged from Object library and dropped in the static cells of the tableView. – bibscy Mar 4 '17 at 14:21


You should use the tag to check if the current textfield is the first responder.

Note: Swift 3.

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // let's say that you are reading the date from an array...
        return myArray.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! TableViewCell

        // here you set the tag
        cell.myTextfield?.tag = indexPath.row

        // ...

        return cell
    }


    func textFieldDidBeginEditing(textField: UITextField) {
        // now, based on textField you can check (tag == myArray.count - 1 means it is the last)
        textField.returnKeyType = (textField.tag == myArray.count - 1) ? .done : .next
    }

Hope that helped.

Learn how to move to the next UITextField after pressing the keyboard The next step will be to assign a unique tag to the text fields located in the cells. In the file UITableView+Extensions.swift. you can find both keyboard  A swift extension that applies mxcl's answer to make this particularly easy (adapted to swift 2.3 by Traveler): extension UITextField { class func connectFields(fields:[UITextField]) -> Void { guard let last = fields.last else { return } for i in 0 ..< fields.count - 1 { fields[i].returnKeyType = .Next fields[i].addTarget(fields[i+1], action: "becomeFirstResponder", forControlEvents


Best way for me.

UITableViewCell

class CustomTableViewCell: UITableViewCell {
     var nextTextField: (() -> Void)?
}

UITableViewDataSource, UITableViewDelegate

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    ...
    cell.nextTextField = { in
        guard let cell = tableView.cellForRow(at: IndexPath(row: indexPath.row + 1, section: 0)) as? CustomTableViewCell else {
            return
        }
        cell.textField.becomeFirstResponder()
    }
    return cell
}

UITextFieldDelegate

...
func textFieldDidBeginEditing(textfield: RCTextField) {
    if viewModel.items.count-1 == textfield.tag {
       textField.returnKeyType = UIReturnKeyType.done
    } else {
       textField.returnKeyType = UIReturnKeyType.next
    }
}
...

iOS 10 and earlier. Weird scrolling and layout issues. When you scroll down on the UITableView and try to edit a text you'll notice weird  Instead what you would want to do is iterate through everything in your underlying data structure. Can you elaborate on what you're trying to do please? – pbush25 Jun 29 '15 at 15:49 He said visible cells , you can do that, perhaps he edited his question – sylvanaar Jun 29 '15 at 16:10


let indexPath = IndexPath(row: index, section: 0); guard let cell = tableView.​cellForRow(at  This blog post will explain how navigation works between views in SwiftUI. When you never worked with SwiftUI before, please read the introduction to SwiftUI to get the basic knowledge. Setting up the NavigationView. When navigating between views, a NavigationView is needed to allow the app to navigate.


textField.text = value as? String. } } // use a text field to display our contents, since that allows editing and showing the keyboard. lazy var textField:UITextField = {. In this tutorial you will learn how to add a header and a footer view to a UITableView. There are two ways that we can add the header and footer, one way is to add it in using Interface Builder and the other way is to do it with code. In this tutorial we will be using both Interface Builder as well as code. Step 1: Setup the UITableView The first thing that we need to do is to set up the


I created a custom cell with a textField. When the button on the same screen as the custom cell is pressed, the text fie. TPKeyboardAvoiding. A drop-in universal solution for moving text fields out of the way of the keyboard in iOS. Introduction. There are a hundred and one proposed solutions out there for how to move UITextField and UITextView out of the way of the keyboard during editing -- usually, it comes down to observing UIKeyboardWillShowNotification and UIKeyboardWillHideNotification, or implementing