在故事板之前的iOS中,我使用了nib并使用以下代码来呈现UIViewControllers视图。我试图找出如何使用故事板来做到这一点。它在调用initWithNib时崩溃。我对如何解决这个问题的所有建议持开放态度。提前谢谢。
folderCollectionView = [[FolderCollectionViewController alloc] initWithNibName:@"FolderCollectionViewController" bundle:nil];
folderView = [folderCollectionView view];
[folderView setFrame:CGRectMake([[self view] bounds].origin.x, [[self view] bounds].origin.y, [[self view] bounds].size.width, [[self view] bounds].size.height)];
folderCollectionView.delegate = self;
[[self view] insertSubview:folderView atIndex:1];
[[self view] bringSubviewToFront:folderView];
[folderView setBackgroundColor:[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f]];
folderView.alpha = 0.0;
[UIView animateWithDuration:1.2f
delay:0.0f
options: UIViewAnimationCurveEaseIn
animations:^{
folderView.alpha = 1.0;
}completion:nil];
答案 0 :(得分:1)
替换
folderCollectionView = [[FolderCollectionViewController alloc] initWithNibName:@"FolderCollectionViewController" bundle:nil];
带
folderCollectionView = [self.storyboard instantiateViewControllerWithIdentifier:@"FolderCollectionViewController" bundle:nil];
确保在界面构建器
中设置标识符
答案 1 :(得分:0)
使用故事板,您通常不会使用iniWithNib方法。你可以通过调用
来实现[self performSegueWithIdentifier:@"segueIdentifier" sender:buttonName];
在您从一个视图控制拖动到另一个视图后,标识符在storyboard文件中设置。然后配置你实现的新视图
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
folderCollectionView = [segue destinationViewController];
...
// Complete the rest of you view initialization here
}
您可以在此处详细了解故事板:Apple's Storyboards
答案 2 :(得分:0)
我遇到了同样的问题。
我是这样做的:
AddsViewController *addsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"AddsViewController"];
[self.navigationController pushViewController:addsViewController animated:YES];