简体   繁体   English

当我们有三个UIViewControllers时如何添加返回按钮

[英]How to add back button when we have three UIViewControllers

I am learning Navigation controller from this link . 我正在从此链接学习导航控制器。

I have created it as per this link. 我已经按照此链接创建了它。 However, now what I want is add one more UIViewController before first where I will have a button as My Recipe Book . 但是,现在我想要的是在第一个之前添加一个UIViewController ,这里我将有一个按钮作为My Recipe Book When I click on this button, I will see the first screen that is there in the example. 当我单击此按钮时,将看到示例中的第一个屏幕。 When I see the second screen (where I will have a list of items (screen 1 in example)), the Navigation bar should have a back button like what I have in above the example in the second screen. 当我看到第二个屏幕(其中将有一个项目列表(示例中的屏幕1))时,导航栏应具有一个后退按钮,就像我在第二个屏幕中的示例上方一样。

Any idea how to get this done? 任何想法如何做到这一点?

I tried adding new UIViewController and adding navigation controller and connecting this UIViewController to first UIViewController in example with MODAL . 我尝试添加新的UIViewController并添加导航控制器,并将此UIViewController连接到第一个UIViewController (例如,使用MODAL

It works, however I don't see back button. 它有效,但是我看不到后退按钮。

I got the answer... Yes I made it finally... 我得到了答案...是的,我终于做到了...

I added new UIViewController and linked this new UIViewController to Navigation controller that is already present. 我添加了新的UIViewController并将此新的UIViewController链接到已经存在的Navigation控制器。

Earlier : 较早:

Navigation Controller >> UIViewController 1 >> UIViewController 2

What I was trying, which was not working 我在尝试什么,没有用

Navigation Controller >> New UIViewController >> Navigation Controller >> UIViewController 1 >> UIViewController 2

Below is what is working 以下是工作原理

Navigation Controller >> New UIViewController >> UIViewController 1 >> UIViewController 2

set title to each view controller's viewDidLoad method using.... 使用...设置每个视图控制器的viewDidLoad方法的标题。

    [self setTitle:@"myViewController"];

and if navigation bar is hidden then make it visible using ...... 如果隐藏了导航栏,则使用......使其可见

[self.navigationController setNavigationBarHidden:NO];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM