ios 如何执行转场

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7845832/
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-08-30 21:58:44  来源:igfitidea点击:

how to perform a segue

iphoneiosxcodestoryboard

提问by chizzle

I would like implement a button to show another view. I have defined the destination ViewController in Storyboard & created a segue (of type push) and gave it an identifier.

我想实现一个按钮来显示另一个视图。我已经在 Storyboard 中定义了目标 ViewController 并创建了一个 segue(类型为 push)并给了它一个标识符。

In my root view controller

在我的根视图控制器中

some method ...

某种方法...

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [btn addTarget:self action:@selector(showDetailView:) forControlEvents:UIControlEventTouchUpInside];

and

- (IBAction)showDetailView:(id)sender {
    [self performSegueWithIdentifier:@"ShowDetail" sender:sender];
}

however it doesn't do anything. I hear a Segue is an object. do I need to have a reference to it / synthesize it in my root view controller class? Any tip would be appreciated. Thank you.

但是它没有做任何事情。我听说 Segue 是一个对象。我需要在我的根视图控制器类中引用它/合成它吗?任何提示将不胜感激。谢谢你。

回答by Martin Ullrich

Edit:
Make sure your root view controller is embedded in a navigation controller. if it isn't, select your view controller in the storyboard designer and choose Editor->Embed In->Navigation Controller in the menu.

编辑:
确保您的根视图控制器嵌入在导航控制器中。如果不是,请在故事板设计器中选择您的视图控制器,然后在菜单中选择 Editor->Embed In->Navigation Controller。

Original:
Double-check the Identifier (storyboard-code) and try setting senderto self. If that doesn't work you can create a Segue object yourself in code.

原文:
仔细检查标识符(故事板代码)并尝试设置senderself. 如果这不起作用,您可以自己在代码中创建一个 Segue 对象。