button created programmatically doesn't respond to target, swift -


i'm creating button in tableview header in section 1.

i so:

func tableview(tableview: uitableview, viewforheaderinsection section: int) -> uiview? {          let header = uiview(frame: cgrectmake(0, 0, tableview.frame.size.width, 40))         header.backgroundcolor = uicolor.greencolor()     if section == 1 {         var button   = uibutton()         button.frame = cgrectmake(100, 100, 100, 50)         button.backgroundcolor = uicolor.greencolor()         button.settitle("button", forstate: uicontrolstate.normal)         button.addtarget(self, action: "action:", forcontrolevents: uicontrolevents.touchupinside)         header.addsubview(button)     }         return header }   func action(sender: uibutton){     println("button pressed") } 

the button appears in section 1 (as should) if press on instead of printing message, nothing happens.

my problem wasn't specifying button.frame correctly. since button outside frame, never called.

 button.frame = cgrectmake(5, 2, tableview.frame.size.width - 5, 18); 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -