xcode 如何将新的视图控制器包含到现有的导航视图中

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

How to include a new view controller to an existing navigation view

iosobjective-cxcodeuiviewuinavigationcontroller

提问by Peter Stuart

I am developing a basic which has a story board like this: enter image description here

我正在开发一个基本的,它有一个这样的故事板: 在此处输入图片说明

When the UIButton is pressed the URL is loaded. If the URL request is succesfull then I have the "Success" view (on on the right) opened.

当按下 UIButton 时,URL 被加载。如果 URL 请求成功,那么我将打开“成功”视图(在右侧)。

It all works fine but I can't seem to get the navigation controller to appear on the Success view. Could someone help me? Also, if the navigation can go on that view, how would I add a "back" button to take the user back to the main view?

一切正常,但我似乎无法让导航控制器出现在“成功”视图中。有人可以帮助我吗?此外,如果导航可以继续该视图,我将如何添加“返回”按钮以将用户带回主视图?

Here is my code so far:

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

UIStoryboard * mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
NSLog(@"%@", status_code);
UIViewController *linkSuccess = [mainStoryboard instantiateViewControllerWithIdentifier:@"linkSuccess"];
[self presentViewController:linkSuccess
                   animated:YES
                 completion:NULL];

Peter

彼得

回答by James

Control drag from the my app controller (the little yellow icon on the lower left in your screenshot) to the Success view controller and it should bring up the box asking you what kind of segue. Because this is a navigation controller you want a push segue. Click on the new arrow going from the my app controller to the success controller in the storyboard that represents your new segue and in the properties inspector give it a name, perhaps something like showSuccess

控制从我的应用程序控制器(屏幕截图左下角的黄色小图标)到成功视图控制器的拖动,它应该会弹出询问你什么样的转场的框。因为这是一个导航控制器,所以你需要一个推送转场。单击从我的应用程序控制器到代表您的新 segue 的故事板中的成功控制器的新箭头,并在属性检查器中为其命名,可能类似于 showSuccess

Then in your URL request successful code use this:

然后在你的 URL 请求成功代码中使用这个:

[self performSegueWithIdentifier:@"showSuccess" sender:self];

Alternatively, if you want to instantiate it yourself (as you have in the code above) you need to add it to the navigation controller. For example:

或者,如果您想自己实例化它(如上面的代码中所示),您需要将其添加到导航控制器中。例如:

UIStoryboard * mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
NSLog(@"%@", status_code);
UIViewController *linkSuccess = [mainStoryboard instantiateViewControllerWithIdentifier:@"linkSuccess"];
[self.navigationController pushViewController:linkSuccess animated:YES];

回答by Vojtech Bartos

You have to extending success view controller from 'My App' controller. Click on 'My App'view controller header, hold ctrl + click on trackpad + move it to success view controller.

您必须从“我的应用程序”控制器扩展成功视图控制器。单击“我的应用程序”视图控制器标题,按住 ctrl + 单击触控板 + 将其移动到成功视图控制器。

Should be work

应该工作