返回到另一个故事板的按钮 [英] Back button to another storyboard

查看:92
本文介绍了返回到另一个故事板的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包含2个故事板的iOS应用.

I am creating an iOS app which consists of 2 storyboards.

这是第二个:

我的目标是iOS 7,因此无法使用情节提要参考.情节提要之间的切换是通过编程方式处理的

I am targeting iOS 7 so I cant use storyboard references. Switch between storyboards is handled programmatically

使用此代码:

 let viewController:UIViewController = UIStoryboard(name: "Warnings", bundle: nil).instantiateViewControllerWithIdentifier("WarningsInitialView") as UIViewController
    self.presentViewController(viewController, animated: true, completion: nil)

我可以使用它来进入第二个故事板.但是,您可以看到第二个情节提要板由Tab Controller组成,并且我要(在两个选项卡上)都需要后退按钮,该按钮将指向主(上一个)情节提要板.我应该如何实现呢?

I can get to the second storyboard using this. However as you can see second storyboard consists of Tab Controller and I want (on both tabs) back button which will point to the main (previous) storyboard. How should I achieve this?

我尝试使用此代码:

AvalanchesBackButton.leftBarButtonItem = UIBarButtonItem (title: "< Spät", style: UIBarButtonItemStyle.Plain, target: self, action: "backButtonClicked")

通过对两个视图使用不同的视图控制器并对它进行硬编码,我将能够实现我想要的.但是,有没有一种方法可以更整洁地做到这一点?就像在容器Tab Controller上实现后退按钮一样,该按钮将指向先前的故事板?

I will be able to achieve what I want by using different view controllers for both views and hardcoding it. But is there a way to do it more cleanly? Like implement a back button on container Tab Controller which will point to previous storyboard?

预先感谢

推荐答案

您以前的ViewController是否已嵌入到Navigation控制器中?因为按"视图控制器会自动添加后退"按钮.

Is your previous ViewController embedded into a Navigation controller? because "pushing" the view controller automatically adds the back button.

self.navigationController?.pushViewController(viewController: UIViewController, animated: Bool)

这篇关于返回到另一个故事板的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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