我尝试在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上。有什么建议吗?
最佳答案
您需要将定义slideViewViewController的行移动到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"];
关于ios - 从非ECSlidingViewController打开ECSlidingViewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15748068/