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.
精彩评论