如何设置模式segue(以编程方式)到push segue [英] How do i set a modal segue (programmatically) to a push segue

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

问题描述

我在我的故事板的导航控制器,但由于种种原因,我必须做出一个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?

这是到目前为止我的代码:

this is my code so far:

- (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一个故事板ID,说详情,然后可以以编程调用该赛格瑞经由:

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

我喜欢这个因为那个故事板继续在视觉上代表应用程序的流程(而不是可能有浮动的场景没有segue)。并且你可以对push和modal segue使用完全相同的构造(并且呈现下一个视图控制器的视图控制器不关心故事板使用哪个)。

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).

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

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