So I have a bunch of buttons on my page, and have them sorted into an array of type [UIButton] and called buttonsArray.
When you click one of these buttons I have their action tied to the goToFacts function which goes along with my segue "goToFactSegue" and passes the information of WHICH button (sender) to my prepare for segue function. My prepareforSegue function confirms that the segue identifier is correct and then sets the variable index to the right number on the DetailViewController page. The way I calculate the correct number to set index to (called whichIndex) is by matching up which index (the Button that was clicked) is in the buttonsArray. my problem is finding the title/name of the button that was clicked (sender) and setting it the theButtonsName so i can search for it in my buttonsArray and find it's index.
TL;DR how do you pull a UIButton's name like you would using .view on a UIImageView
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "goToFactSegue" {
// send info to next page
if let whereToGo = segue.destinationViewController as? DetailViewController {
let theButtonsName = sender!.******** as! UIButton
if let whichIndex = find(buttonsArray, theButtonsName) {
whereToGo.index = whichIndex
}}
}
}
@IBAction func goToFacts(sender: UIButton) {
performSegueWithIdentifier("goToFactSegue", sender: sender)
}
I've searched through all the possibilities xcode suggests and nothing interacts with UIButton, read up on the doc and all they talk about is .titleLabel which is that actual text (And No, .titleLabel doesn't work) Also tried the usual suspects (variations of named...etc)
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "goToFactSegue" {
if let whereToGo = segue.destinationViewController as? DetailViewController {
let button = sender as! UIButton
let theButtonsName = button.titlelabel?.text
if let whichIndex = find(buttonsArray, theButtonsName) {
whereToGo.index = whichIndex
}
}
}
}