CCNextField is an an extension to UIKIT's UITextField
with an easy usage to handle switching to the next UITextField
when tapping the return key.
textField.nextField(resigns: true) {
print("noice")
}
To run the example project, clone the repo, and run pod install
from the Example directory first.
In Xcode with your project open, go to File > Add Packages... > paste the following link in the search bar:
https://github.com/HiConceit/CCNextField
CCNextField is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'CCNextField'
Copy the CCNextField folder to your project.
// Conform your UIViewController/UITableViewConroller to UITextFieldDelegate
class ViewController: UIViewController, UITextFieldDelegate {
// Connect textFields from storyboard
@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Add all your textFields
let textFields = [nameTextField,
emailTextField,
passwordTextField]
// Connect textFields to delegate & set textField.tag
for field in textFields {
field!.delegate = self
field!.tag = textFields.firstIndex(of: field)!
}
}
// Get current textField and call nextField.
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
// Set (resigns) to true to hide keyboard, or false to just execute your function.
textField.nextField(resigns: true) {
print("noice")
}
return false
}
}
2022 Conceit LLC
CCNextField is available under the MIT license. See the LICENSE file for more info.