DropDown on swift

0

I'm using a dropdown type using this 1 project, and now I wanted to select one of the items that is inside it and close the dropdown and the chosen item appears on the button label this all in swift, can anyone help me here?

Thank you

    
asked by anonymous 11.02.2016 / 12:48

1 answer

1

First you have to create an IBOutlet for the button that will have its title changed: (Do not forget to connect it to the button on the storyboard)

@IBOutlet var botao: UIButton!

There in the "func createPicker ()" add the following line in the loop where you create the popup options:

button.addTarget(self, action: "clicado:", forControlEvents: .TouchUpInside)

The above line tells the button being created, which method it should call when it is 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()
}
    
14.02.2016 / 02:38