स्विफ्ट 2.0 संस्करण:
//Declared at top of view controller
var accessoryDoneButton: UIBarButtonItem!
let accessoryToolBar = UIToolbar(frame: CGRectMake(0,0,UIScreen.mainScreen().bounds.width, 44))
//Could also be an IBOutlet, I just happened to have it like this
let codeInput = UITextField()
//Configured in viewDidLoad()
self.accessoryDoneButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: #selector(self.donePressed(_:)))
self.accessoryToolBar.items = [self.accessoryDoneButton]
self.codeInput.inputAccessoryView = self.accessoryToolBar
स्विफ्ट 4:
//Declared at top of view controller
var accessoryDoneButton: UIBarButtonItem!
let accessoryToolBar = UIToolbar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 44))
//Could also be an IBOutlet, I just happened to have it like this
let codeInput = UITextField()
//Configured in viewDidLoad()
self.accessoryDoneButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.done, target: self, action: #selector(self.donePressed))
self.accessoryToolBar.items = [self.accessoryDoneButton]
self.codeInput.inputAccessoryView = self.accessoryToolBar
func donePressed() {
//Causes the view (or one of its embedded text fields) to resign the first responder status.
view.endEditing(true)
}
UIToolBar Documentation
'inputAccessoryView' documentation
स्रोत
2016-08-30 23:23:34
धन्यवाद, लेकिन मैं भी एक प्रमुख विधि से कॉल करना चाहते हैं तो क्या होगा? – Vins
मुझे आपको नहीं मिला। आप क्या कॉल करना चाहते हैं? –
मेरे पास एक तरीका है जो पाठ को डेटाबेस [सेव सेवस्ट्रिंग] में सहेजता है; – Vins