xcode 我可以在没有 StoryBoard 转场的情况下转到另一个视图吗?只是从视图中调用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11473985/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:53:08  来源:igfitidea点击:

Can I go to another view without a StoryBoard segue? Just with a call from a view?

objective-cxcodesegue

提问by alex

SO I would like to know if there is a possibility to make a call from a view in the code to go to another view, not using segue.

所以我想知道是否有可能从代码中的视图调用以转到另一个视图,而不是使用 segue。

Thanks for the help.

谢谢您的帮助。

回答by Dan F

Yes, if you are using a navigation controller, you simply need to push onto the navigation controller:

是的,如果您使用的是导航控制器,您只需将其推到导航控制器上:

[self.navigationController pushViewController:otherViewCon animated:YES];

Or, if you want a modal transition:

或者,如果您想要模态转换:

[self presentModalViewController:otherViewCon animated:YES];

This is all assuming selfis a UIViewController.

这一切都假设self是一个 UIViewController。

To get otherViewConfrom a storyboard designed view controller:

要从otherViewCon故事板设计的视图控制器中获取:

otherViewCon = [self.storyboard instantiateViewControllerWithIdentifier:@"Other View"];

回答by Dustin

Example of presenting a popover:

呈现弹出框的示例:

    //Declare popover controller
    UIPopoverController *paparazzi;

   //Just some Interface Builder action (could be triggered by a button)
    - (IBAction)sigFocus:(id)sender
    {
        //A view controller being made from a xib file
        SigPopView *temp = [[SigPopView alloc] initWithNibName:@"SigPopView" bundle:nil];

        //Sets the view controller to be displayed
        paparazzi = [[UIPopoverController alloc] initWithContentViewController:temp];

        //Set size
        [paparazzi setPopoverContentSize:CGSizeMake(480,179)];

        //Show controller
        [paparazzi presentPopoverFromRect:theSignature.frame inView:(UIView *)self.delegate permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }