IOS Customkeyboard在nsuserdefault中获取nil值

时间:2015-08-01 08:57:31

标签: ios nsuserdefaults custom-keyboard

我正在使用appextension定制键盘。它基于单手键盘。当用户需要用右手访问时,需要选择右手,如果用户需要用左手键入,用户可以选择左侧键盘。我在Nsuserdefault中为键布局设置了值。 这是我的尝试。

  - (void)viewDidLoad {//group.keyboaredExtention
_defaultvalue = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.example.project"];
[_defaultvalue setBool:YES forKey:@"Layout"];
[_defaultvalue synchronize];

 //This is my viewcontroller which contain code for setting left and right keyboard.
 - (IBAction)RightAction:(id)sender {
_defaultvalue = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.example.project"];
[_defaultvalue setBool:YES forKey:@"Layout"];
[_defaultvalue synchronize]; 
[_rightView setBackgroundColor:[UIColor colorWithRed:220.0/255.0 green:214.0/255.0 blue:63.0/255.0 alpha:1.0]];
[_leftView setBackgroundColor:[UIColor clearColor]];
  [_rightView setBackgroundColor:[UIColor clearColor]];
[_leftView setBackgroundColor:[UIColor colorWithRed:0.0/255.0 green:145.0/255.0 blue:196.0/255.0 alpha:1.0]];

}

- (IBAction)leftAction:(id)sender {
 _defaultvalue = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.example.project"];
[_defaultvalue setBool:NO forKey:@"Layout"];
[_defaultvalue synchronize];

[_rightView setBackgroundColor:[UIColor clearColor]];
[_leftView setBackgroundColor:[UIColor colorWithRed:0.0/255.0 green:145.0/255.0 blue:196.0/255.0 alpha:1.0]];

}

这是我的键盘viewcontroller.m文件。

      -(void)LoadKeyboardview
    {


if(isPortrait)
{
    _defaultvalue = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.example.project"];

    NSLog(@"==%@",@"asdfasf");
    if([[NSUserDefaults standardUserDefaults]integerForKey:@"Layout"] == NO)
     {
        NSLog(@"True");
    }else{
        NSLog(@"False");
    }

    if([_defaultvalue boolForKey:@"Layout"] == YES)
    {
        self.ObjKeyLayout=[[[NSBundle mainBundle]loadNibNamed:@"keyboardLayout" owner:nil options:nil]objectAtIndex:0];
        [self addGesturToKeyBoard];
        self.view =self.ObjKeyLayout;
        [self updateCustomHeight];

    }
    else{


        self.ObjKeyLayout=[[[NSBundle mainBundle]loadNibNamed:@"leftLayout" owner:nil options:nil]objectAtIndex:0];
        [self addGesturToKeyBoard];




        self.view =self.ObjKeyLayout;
        [self updateCustomHeight];

    }


}
else
{


    self.ObjKeyLayout=[[[NSBundle mainBundle]loadNibNamed:@"LandscapLayout" owner:nil options:nil]objectAtIndex:0];
    [self addGesturToKeyBoard];
     //[self.ObjKeyLayout setUserInteractionEnabled:YES];
    self.inputView =self.ObjKeyLayout;
    [self updateCustomHeight];

}
}

注意: - 我在viewcontroller.m文件中获得nsuserdefault的值,用于左键码" 0"对于右键盘" 1"。但无法在Keyboardviewcontroller.m文件中获取值。 Po [_defaultuder boolforkey:@"布局"] 显示我的价值为零。

那么,我怎样才能在Keyboardlayout.m文件中获得价值?

0 个答案:

没有答案
相关问题