如何将模态转场(以编程方式)设置为推送转场 [英] How do i set a modal segue (programmatically) to a push segue

查看:31
本文介绍了如何将模态转场(以编程方式)设置为推送转场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的故事板中有一个导航控制器,但出于一个原因,我必须以编程方式制作一个 segue,但我如何以编程方式制作一个 push segue?

i have an navigation controller in my storyboard, but for one reason i have to make one segue programmatically, but how do i make a push segue programmatically?

这是我目前的代码:

- (IBAction)nextviewButton:(id)sender {
    HolesViewController *Holes = [self.storyboard instantiateViewControllerWithIdentifier:@"HolesViewController"];
    Holes.nameString = self.NameField.text;

    [self presentViewController:Holes animated:YES completion:nil];
}

推荐答案

另外,我实际上更喜欢在我的故事板中定义一个 segue,但不是源自按钮,而是源自视图控制器本身,例如:

Alternatively, I actually prefer to define a segue right in my storyboard, but rather than originating from the button, I have it originate from the view controller itself, e.g.:

然后,给该 segue 一个storyboard id",说Details",然后您可以通过以下方式以编程方式调用该 segue:

Then, give that segue a "storyboard id", say "Details", and then you can invoke that segue programmatically via:

[self performSegueWithIdentifier:@"Details" sender: ...]; // you can specify either the button or `self` for the `sender

我喜欢这样,因为这样,故事板继续在视觉上代表应用程序的流程(而不是可能有没有转场的场景漂浮在那里).您可以对 push 和 modal segues 使用完全相同的结构(并且呈现下一个视图控制器的视图控制器并不关心情节提要使用哪一个).

I like this because that way, the storyboard continues to visually represent the flow of the app (as opposed to possibly having scenes floating out there with no segues). And you can use the exact same construct for both push and modal segues (and the view controller that's presenting the next view controller doesn't care which one the storyboard uses).

这篇关于如何将模态转场(以编程方式)设置为推送转场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆