Using “next" as a return key
- Usage: set delegate and nextField of textField (storyboard or code)
This commit is contained in:
parent
2519472ba2
commit
c10f6a7ba0
4 changed files with 87 additions and 28 deletions
34
pass/Helpers/UITextFieldExtension.swift
Normal file
34
pass/Helpers/UITextFieldExtension.swift
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// UIViewControllerExtionsion.swift
|
||||
// pass
|
||||
//
|
||||
// Created by Yishi Lin on 5/4/17.
|
||||
// Copyright © 2017 Yishi Lin. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
private var kAssociationKeyNextField: UInt8 = 0
|
||||
|
||||
extension UITextField {
|
||||
@IBOutlet var nextField: UITextField? {
|
||||
get {
|
||||
return objc_getAssociatedObject(self, &kAssociationKeyNextField) as? UITextField
|
||||
}
|
||||
set(newField) {
|
||||
objc_setAssociatedObject(self, &kAssociationKeyNextField, newField, .OBJC_ASSOCIATION_RETAIN)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension UIViewController {
|
||||
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||
if textField.nextField != nil {
|
||||
textField.nextField?.becomeFirstResponder()
|
||||
} else {
|
||||
textField.resignFirstResponder()
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue