0
I’m using a kind of dropdown using this project 1, and now wanted to select one of the items that is inside it and close the dropdown and the chosen item appear on the button label this all in Swift, someone can help me here?
Thank you
0
I’m using a kind of dropdown using this project 1, and now wanted to select one of the items that is inside it and close the dropdown and the chosen item appear on the button label this all in Swift, someone can help me here?
Thank you
1
First you have to create an Iboutlet for the button that will have your title changed: (Don’t forget to connect it to the button on the storyboard)
@IBOutlet var botao: UIButton!
There in "func createPicker()" add the following line in the loop where you create the popup options:
button.addTarget(self, action: "clicado:", forControlEvents: .TouchUpInside)
The line above tells the button being created, which method q it should call when clicked.
Then you create the method:
func clicado(sender : UIButton){
// acha o titulo de acordo com a tag do botão clicado
let feeling = properties.moods[sender.tag].first!
// atribui o titulo achado ao botão do IBOutlet criado
self.botao.setTitle(feeling.1, forState: .Normal)
// fecha o picker
self.closePicker()
}
Browser other questions tagged ios swift dropdown button
You are not signed in. Login or sign up in order to post.
Ccastro, can you tell me the reason for the two dots at the end of the string in the method name in the action (clicked)?
– JdsMedeirosBR
Do you speak these two points? -> function clicked(Sender : Uibutton) it specifies the type q will be received by the method. In this case, the Sender will receive a Uibutton, that is, the Uibutton q has been clicked. So when I do Sender.tag below, I’m taking the Uibutton tag that was clicked, so I can identify which was the option
– CCastro
No, inside the same addTarget string... action: "clicked:"
– JdsMedeirosBR
I don’t know if it’s clear?
– CCastro
Yeah, he was, yeah! However it is very strange you pass a self parameter and in the second parameter be required to put two points for the first parameter to work.
– JdsMedeirosBR
Jadson, a fix. Looking at the documentation recently, the first parameter is not the button, but the target. That is, the class where the function to be called was defined.
– CCastro