1

在故事板之前的 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];
4

3 回答 3

1

代替

   folderCollectionView = [[FolderCollectionViewController alloc] initWithNibName:@"FolderCollectionViewController" bundle:nil];

   folderCollectionView = [self.storyboard instantiateViewControllerWithIdentifier:@"FolderCollectionViewController" bundle:nil];

确保在界面生成器中设置标识符

在此处输入图像描述

于 2012-09-29T07:36:49.413 回答
0

对于情节提要,您通常不会使用 iniWithNib 方法。你通过调用来做到这一点

[self performSegueWithIdentifier:@"segueIdentifier" sender:buttonName];

在您从一个视图拖动到另一个视图后,该标识符在情节提要文件中设置。然后配置您实现的新视图

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    folderCollectionView = [segue destinationViewController];
    ...
    // Complete the rest of you view initialization here
}

您可以在此处阅读有关故事板的更多信息:Apple 的故事板

于 2012-09-29T05:32:53.400 回答
0

我有同样的问题。

我是这样做的:

AddsViewController *addsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"AddsViewController"];
[self.navigationController pushViewController:addsViewController animated:YES];
于 2012-09-29T08:46:16.943 回答