swift - UIButton button titles changes by itself on click of another button to its title -
i have 12 buttons in app. last button title changes title of other button press. example, if button 3's title joe, last button (tag 12
) automatically changes joe (even though there no code change title. weird!
ps: set title in code:
func btnseticon(btnnumber: int){ println("in btnseticon btnnumber = \(btnnumber)") btn.titlelabel?.numberoflines = 2 btn.titlelabel?.textalignment = nstextalignment.center btn.titlelabel?.adjustsfontsizetofitwidth = true detail1.keyboardtype = uikeyboardtype.asciicapable detail1.rightviewmode = uitextfieldviewmode.never switch btnnumber { case 1: btn.settitle("bucket\nlist", forstate: .normal) case 2: btn.settitle("shop\nlist", forstate: .normal) case 3: btn.settitle("grocery\nlist", forstate: .normal) case 4: btn.settitle("to do\nlist", forstate: .normal) case 5: btn.settitle("notes\nto self", forstate: .normal) case 6: btn.settitle("sos\nlist", forstate: .normal) case 7: btn.settitle("phone\n#'s", forstate: .normal) case 8: btn.settitle("event\nlist", forstate: .normal) case 9: btn.settitle("your 1\nlist", forstate: .normal) case 10: btn.settitle("your 2\nlist", forstate: .normal) case 11: btn.settitle("your 3\nlist", forstate: .normal) case 12: btn.settitle("your 4\nlist", forstate: .normal) default: btn.settitle("✚", forstate: .normal) } }
you not passing variable btn
btnseticon()
, must property of viewcontroller
. btn
left set last button added viewcontroller
, when call btnseticon()
, button gets updated.
perhaps want in btnseticon()
:
if let btn = self.view.viewwithtag(btnnumber) as? uibutton { // update btn in here }
Comments
Post a Comment