宏定义,以及宏的存储

来源:互联网 发布:玻璃裁切软件 编辑:程序博客网 时间:2024/06/08 19:48

废话不多说!见代码:


.h文件中  

//                值                         键

#define switchValue @"PushSwitch"

.m文件中

-(void)airplaneModeSwitch:(UISwitch*)sender

{

    if (airplaneModeSwitch.on) {

        [APServiceregisterForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |

                                                      UIRemoteNotificationTypeSound |

                                                       UIRemoteNotificationTypeAlert)];

        

        NSLog(@"打开");

    }

    else{

        [[UIApplicationsharedApplication] unregisterForRemoteNotifications];

        [APServiceregisterForRemoteNotificationTypes:UIRemoteNotificationTypeNone];

        NSLog(@"关闭");

    }

    [[NSUserDefaultsstandardUserDefaults] setBool:airplaneModeSwitch.onforKey:switchValue];

    [[NSUserDefaultsstandardUserDefaults] synchronize];//命令直接同步到文件里,来避免数据的丢失                                         //存储内容

}


-(void) viewWillAppear:(BOOL)animated{

    [superviewDidAppear:animated];

    NSUserDefaults *lanUser = [NSUserDefaultsstandardUserDefaults];

    self.navigationItem.title= [[lanUserobjectForKey:@"dic"]objectForKey:@"title"];


    BOOL b=[[NSUserDefaultsstandardUserDefaults] boolForKey:switchValue];                                                                                   //读取内容

    airplaneModeSwitch.on=b;


    [tviewreloadData];

}


原创粉丝点击