开发者

Objective C - Help with UIButton showing variable Titles

First off I am a rookie so any help is appreciated. I have written the following code to change the title of the button every time it is initiated. When I test the code, I can see the new button label for a fraction of a second and then the button is blank again (as it had started off). I only see the first three touches, so I am thinking that there is also something wrong with my counting method. The code is as follows:

-(IBAction)pressButton:(id)sender {
st开发者_如何学Pythonatic int counter = 0;

if (counter == 0) {
    [[sender titleLabel] setText:@"not answered"];
}else if (counter == 1) {
    [[sender titleLabel] setText:@"Pressed Once"];
}else if (counter == 2) {
    [[sender titleLabel] setText:@"Pressed Twice"];
}
counter += 1;

if (counter >2) {
    counter = 0;
}
}

Thank you in advance for your help!


You want to use:

[(UIButton *)sender setTitle:@"XXX" forState:UIControlStateNormal];

Setting the label directly isn't going to work because it's manipulated internally by the button logic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜