I am creating a keyboard which has multiple pages of keys, like the iOS standard keyboard. The keys are created with this code:
override func viewsDidLoad(){
super.viewDidLoad()
generateKeys()
}
func generateKeys() {
switch keysDisplayed {
case 0 :
let buttonTitles1 = ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"]
var row1 = createRowOfButtons(buttonTitles1)
self.view.addSubview(row1)
row1.translatesAutoresizingMaskIntoConstraints = false
addConstraintsToInputView(self.view, rowViews: [row1])
case 1 :
//similar to case 0
default:
keysDisplayed = 0
}
When the user clicks the button to change the keyboard page, keysDisplayed is incremented by 1 and generateKeys() is ran again.
However, (maybe you have noticed this already) there is no code to hide or remove buttons, so if I switch between pages, buttons are simply added to the UIView and they pile up.
My questions are the following: What is best in terms of efficiency? Removing the buttons and creating them as needed, or creating all of the buttons at once and then hiding the buttons and revealing them as needed? Is there a different solution I don't know about? Is there a better way to do what I am trying to do? Further, how do I implement your suggestion?
My attempts at this point have been to remove the buttons, but I cannot identify how to do this properly.