xcode 我如何将模态转场(以编程方式)设置为推送转场
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15637945/
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
How do i set a modal segue (programmatically) to a push segue
提问by lennartk
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];
}
回答by Rob
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,但不是源自按钮,而是源自视图控制器本身,例如:
Then, give that segue a "storyboard id", say "Details", and then you can invoke that segue programmatically via:
然后,给该 segue 一个“故事板 id”,说“详细信息”,然后您可以通过以下方式以编程方式调用该 segue:
[self performSegueWithIdentifier:@"Details" sender: ...]; // you can specify either the button or `self` for the `sender
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)。并且您可以对推送和模式转场使用完全相同的构造(并且呈现下一个视图控制器的视图控制器不关心故事板使用哪个)。
回答by lennartk
[self.navigationController pushViewController:Holes animated:YES];
Got it
知道了