从非ECSlidingViewController打开ECSlidingViewController

时间:2013-04-01 17:16:41

标签: ios uiviewcontroller sliding

我已尝试在IBAction上访问ECSlidingViewController。但是,当我尝试以下代码时:

-(IBAction)openNewPage:(id)sender{ //IV

UIStoryboard *storyboard;
ECSlidingViewController *slidingViewController = (ECSlidingViewController *)[storyboard instantiateViewControllerWithIdentifier:@"IV"];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
}

slidingViewController.topViewController = [storyboard instantiateViewControllerWithIdentifier:@"FirstTop"];

}

我收到以下错误:

 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

我在按钮上尝试了一个模态动作,'touchupinside'将落在InitialViewController上。对此有何建议?

1 个答案:

答案 0 :(得分:1)

您需要将定义slidingViewController的行移动到if-else-if子句下面,因为当前的故事板将是nil。

UIStoryboard *storyboard;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
}
ECSlidingViewController *slidingViewController = (ECSlidingViewController *)[storyboard instantiateViewControllerWithIdentifier:@"IV"];
slidingViewController.topViewController = [storyboard instantiateViewControllerWithIdentifier:@"FirstTop"];