开发者

Switch boolean through UIButton

I'm a newbie to iPhone dev...

开发者_JAVA百科

I want a boolean Variable which switches between YES and NO when I click on a UIButton. Really easy I think ?! But I weren't able to find anything. :(

Thx :) Sebastian


The iPhone doesn't use toggle buttons because they're to difficult to use with a touch interface. It's too easy for a user to tap twice.

Instead you use a UISwitch control. You set up an action method just like a regular button and in the action method you check the UISwitch control's on property like so:

-(IBAction) switchChanged:(id) sender{
    if ([sender class] == [UISwitch class]) { //belt and suspenders
        myBooleanVar=sender.on;
    }
}

You can set up a toggle button but its a pain and will confuse users.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜