如何使用ViewController设置InputView

时间:2016-06-11 10:38:50

标签: ios objective-c

self.view = [[[NSBundle mainBundle] loadNibNamed:@"KeyboardView" owner:self options:nil] objectAtIndex:0];
self.inputView = (UIInputView*)self.view;

上面的代码是用于将Nib文件设置为Inputview,这是有效的,但是下面的代码不起作用...

NewViewController * myViewController = [[UIStoryboard storyboardWithName:@"Keyboard"  bundle:nil] instantiateViewControllerWithIdentifier:@"NewView"];
self.view = myViewController.view;

self.inputView = (UIInputView*)self.view;

1 个答案:

答案 0 :(得分:0)

请检查故事板名称。它"键盘"或者不同的东西。您的写包是nil但它应该是[NSBundle mainBundle]

NewViewController * myViewController = [[UIStoryboard storyboardWithName:@"Keyboard"  bundle:nil] instantiateViewControllerWithIdentifier:@"NewView"];

检查一下:

NewViewController *vc =[[UIStoryboard storyboardWithName:@"MainStoryboard"
                               bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"NewView"];