开发者

Switch boolean through UIButton

开发者 https://www.devze.com 2022-12-20 06:10 出处:网络
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.

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

精彩评论

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