Is there a method to store the state of a UISwitch with NSUserDefaults?
If the state is ON I d like to set some action...
Can I do this?
Thanks!
Is there a method to store the state of a UISwitch with NSUserDefaults?
If the state is ON I d like to set some action...
Can I do this?
Thanks!
热帕韦2的答案是好的,也能很好地促进大片部分控制(超过2个州)。 但是,如果你只想储存2个州,那么为什么不只使用<条码>。
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:switchState forKey:@"mySwitchValueKey"];
并公布:
BOOL swichState = [userDefaults boolForKey:@"mySwitchValueKey"];
仇恨更简单,甚至根本不成规律,不扼制反向和改换。
储蓄:
- (void)mySwitchAction:(id)sender
{
if (sender == mySwitch) {
BOOL mySwitchValue = [ sender isOn ];
NSString *tmpString = mySwitchValue ? @"1" : @"-1" ;
NSUserDefaults *myNSUD = [NSUserDefaults standardUserDefaults];
[ myNSUD setObject:tmpString forKey: @"mySwitchValueKey" ];
[ myNSUD synchronize ];
// do other stuff/actions
}
}
从挽救的国家开始:
NSUserDefaults *myNSUD = [NSUserDefaults standardUserDefaults];
NSString *tmpString = [ myNSUD stringForKey: @"mySwitchValueKey"];
BOOL mySwitchValue = NO; // or DEFAULT_VALUE
if (tmpString != nil) {
mySwitchValue = ( [ tmpString intValue ] == 1 );
}
[mySwitch setOn: mySwitchValue];
I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...
HI, In our application i am using corelocationframework when opening application a alert for allow and dont allow.when clicking on the allow for current location we will show current location.When ...
Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...
我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......
我希望我与四舍五入的累进角进行网上讨论。
我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。
We have a restaurant table that has lat-long data for each row. We need to write a query that performs a search to find all restaurants within the provided radius e.g. 1 mile, 5 miles etc. We have ...
I like to write bash shell scripts on my iPhone, put them in an app folder with an icon, plist, etc., so they execute like apps by tapping their icon on SpringBoard. This is not interactive like ...