简体   繁体   中英

NSUserdefault doubts

i have a view which has an option fullscreen view,i have done the coding with help of switchcontroller,but after fullscreen is switch to on and redirected to anotherpage and comes back it changes to default screen not fullscreen without swithcoff the switchcontroller,so i put NSUserDefault for storing the value but no luck this is my code

 -(IBAction)_clickbtnfullscreen:(id)sender
    {
        if(switchcontrolsplitf.on){

            [switchcontrolsplitf setOn:YES animated:YES];
//i put here the nsuserdeafult
            [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"fullscreenn"];
     CGRect frame = tab.frame;
            CGRect imageframe = btnShowHide.frame;
            CGRect viewframe = hideviewoftab.frame;
            CGRect lblframe = _lblshowhide.frame;
            CGRect lblmalframe = _lblmalaylan.frame;
            CGRect viewwframee= sliderView.frame;


            if (!self.isExpandedfullscreen)
            {

                btnShowHide.enabled  = NO;
                switchcontrolsplitf.enabled =YES;
                tab.scrollEnabled=YES;
                self.isExpandedfullscreen = YES;
                table.frame = CGRectMake(4, 48, 311, 20);
                if (frame.origin.y -=420) {

                    tab.frame = frame;
                }
                if (imageframe.origin.y -=420) {
                    btnShowHide.frame =imageframe;
                }
                if (viewframe.origin.y -=420) {
                    hideviewoftab.frame =viewframe;
                }
                if (lblframe.origin.y -=420) {
                    _lblshowhide.frame =lblframe;
                }
                if (viewwframee.origin.y -=420) {
                    sliderView.frame =viewwframee;
                }
                if (lblmalframe.origin.y -=420) {
                    _lblmalaylan.frame =lblmalframe;
                }
            }
        }
       else 
            {
                CGRect frame = tab.frame;
                CGRect imageframe = btnShowHide.frame;
                CGRect viewframe = hideviewoftab.frame;
                CGRect lblframe = _lblshowhide.frame;
                CGRect lblmalframe = _lblmalaylan.frame;
                CGRect viewwframee= sliderView.frame;
               self.isExpandedfullscreen = NO;

            [switchcontrolsplitf setOn:NO animated:YES];
            //[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"lowlight"];

            tab.scrollEnabled=NO;
            switchcontrolsplitf.enabled =YES;
            table.frame = CGRectMake(4, 48, 311, 387);
            btnShowHide.enabled  = YES;
            if (frame.origin.y +=420) {

                tab.frame = frame;
            }
            if (imageframe.origin.y +=420) {
                btnShowHide.frame =imageframe;
            }
            if (viewframe.origin.y +=420) {
                hideviewoftab.frame =viewframe;
            }
            if (lblframe.origin.y +=420) {
                _lblshowhide.frame =lblframe;
            }
            if (viewwframee.origin.y +=420) {
                sliderView.frame =viewwframee;
            }
            if (lblmalframe.origin.y +=420) {
                _lblmalaylan.frame =lblmalframe;
            }

        }

in viewwillappear

- (void)viewWillAppear:(BOOL)animated{
  BOOL fullscreenn = [[NSUserDefaults standardUserDefaults] boolForKey:@"fullscreenn"];
    if (fullscreenn) {
       [switchcontrolsplitf setOn:YES animated:YES];
    }

How to solve this.please help me. Thanks

after setting your value, you need to synchronize ie save it

      [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"fullscreenn"];
      [[NSUserDefaults standardUserDefaults] synchronize];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM