ios - Button does not deallocate -
var exitimg: uiimage! var exitbutton: uibutton! func missilehitaction(sender:uibutton!) { self.view.viewwithtag(12221)?.removefromsuperview() exitimg = nil exitbutton = nil } override func viewdidload() { super.viewdidload() exitimg = uiimage(contentsoffile: "/users/joca/desktop/game_dev/missile_gun1") exitbutton = uibutton.buttonwithtype(uibuttontype.system) uibutton exitbutton.frame = cgrectmake(5, 285, 70, 30) exitbutton.imageview?.tag = 12221 exitbutton.setbackgroundimage(exitimg, forstate: uicontrolstate.normal) exitbutton.addtarget(self, action: "missilehitaction:", forcontrolevents: uicontrolevents.touchupinside) self.view.addsubview(exitbutton)
}
this sample test project deallocating buttons, on button press button should deallocated, not :(
you creating button, not setting tag. instead, setting image view's tag. instead of:
exitbutton.imageview?.tag = 12221 i think intended:
exitbutton.tag = 12221 ios iphone button swift
No comments:
Post a Comment