将它链接到Storyboard中的某个视图控制器?

时间:2012-05-10 10:55:23

标签: iphone objective-c ios storyboard xib

我有一个动作,我需要链接到故事板中的某个视图。我目前在下面的代码链接到Storyboard的第一个视图。如何将其链接到Storyboard中的某个视图控制器?仅供参考 - 此链接来自xib文件,该文件不是故事板的一部分,并且工作正常。谢谢

  - (IBAction)continueWithoutLoginButtonTouchHandler:(id)sender 
    {

        UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        UIViewController* initialHelpView = [storyboard instantiateInitialViewController];

        initialHelpView.modalPresentationStyle = UIModalPresentationFormSheet;
        [self presentModalViewController:initialHelpView animated:YES];
    }

我想知道方法:instantiateViewControllerWithIdentifier:然后识别故事板中的一个视图会起作用。

 - (IBAction)continueWithoutLoginButtonTouchHandler:(id)sender 
{

    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
   // UIViewController* viewController = [storyboard instantiateInitialViewController];

    UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"RotationVC"];

    viewController.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentModalViewController:viewController animated:YES];
}

感谢您的帮助

1 个答案:

答案 0 :(得分:2)

使用方法:instantiateViewControllerWithIdentifier:然后识别故事板中的一个视图:

 - (IBAction)continueWithoutLoginButtonTouchHandler:(id)sender 
{

    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
   // UIViewController* viewController = [storyboard instantiateInitialViewController];

    UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"RotationVC"];

    viewController.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentModalViewController:viewController animated:YES];
}