我有一个具有全屏视图选项的视图,我已经在switchcontroller的帮助下完成了编码,但是在全屏打开并重定向到另一页并返回后,如果不关闭switchcontroller,它将变为默认全屏而不是全屏,所以我把NSUserDefault用于存储值,但是没有运气,这是我的代码

 -(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;
            }

        }


看来会出现

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


该如何解决。请帮助我。
谢谢

最佳答案

设置值后,您需要synchronize即保存它

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

关于iphone - NSUserdefault怀疑,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8907557/

10-10 03:58