iphone - Issues in setting UIButton title in its click event -


i'm trying change title of button when user press on following code:

- (ibaction) hidekb: (uibutton *) sender {      sender.titlelabel.text = @"↓"; } 

but when click app crashes , can't understand why.

removing sender stuff, button works no problems.

the correct method signature action is

- (ibaction)action:(id)sender 

your app crashing because object being sent message doesn't understand.

try replacing code along lines of:

- (ibaction)hidekb:(id)sender {     uibutton *button = (uibutton *)sender;     [button settitle:@"↓" forstate:uicontrolstatenormal]; } 

as may notice i've changed line sets button title. because should never manipulate uibutton's titlelabel property directly, rather should using appropriate setter method shown above.

edit: clarify, controls allow use dot notation edit text property of titlelabel. however, uibutton instances support different titles (as images , background images) depending on state they're in.

if you're wondering why uibutton in 1 of several different states, example see buttons "greyed out". means buttons in uicontrolstatedisabled state. can find list of possible states control in documentation.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -