Ok, the changes I made to the code as @sweepez suggested seem more logical, except now when I simulate the app, I can't even open the first textfield to start typing if that makes sense. Is there a way to set an active TextField for the first one or based on what the user taps on?
if (textField == quarterNum){
doneButton.tag = 25
} else if (textField == dimeNum) {
doneButton.tag = 10
} else if (textField == nickelNum) {
doneButton.tag = 5
} else {
doneButton.tag = 1
}
return false
}
func doneBttnPressed (barButton: UIBarButtonItem) {
if (barButton.tag == 25) {
dimeNum.becomeFirstResponder()
} else if (barButton.tag == 10) {
nickelNum.becomeFirstResponder()
} else if (barButton.tag == 5) {
pennyNum.becomeFirstResponder()
}
}
here is what I encounter when I move all of that into the viewDidLoad fuction. I have nothing to compare to the textfields in order to set the tag on them.
override func viewDidLoad() {
super.viewDidLoad()
quarterNum.delegate = self
dimeNum.delegate = self
nickelNum.delegate = self
pennyNum.delegate = self
////Background image///////
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "money1.png")!)
//Making A toolbar
let keyboardDoneButtonShow = UIToolbar(frame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height/17))
//Setting the style for the toolbar
keyboardDoneButtonShow.barStyle = UIBarStyle.Black
//Making the done button and calling the textFieldShouldReturn native method for hidding the keyboard.
let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Done, target: self, action: "doneBttnPressed:")
let flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
let toolbarButton = [flexSpace,doneButton]
keyboardDoneButtonShow.setItems(toolbarButton, animated: false)
quarterNum.inputAccessoryView = keyboardDoneButtonShow
dimeNum.inputAccessoryView = keyboardDoneButtonShow
nickelNum.inputAccessoryView = keyboardDoneButtonShow
pennyNum.inputAccessoryView = keyboardDoneButtonShow
if (textField == quarterNum){
doneButton.tag = 25
} else if (textField == dimeNum) {
doneButton.tag = 10
} else if (textField == nickelNum) {
doneButton.tag = 5
} else {
doneButton.tag = 1
}
}