Back button to another storyboard

半腔热情 提交于 2019-12-12 17:30:32

问题


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

This is the second one:

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

Using this code:

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

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?

I have tried using this code:

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

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?

Thanks in advance


回答1:


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)


来源:https://stackoverflow.com/questions/35046445/back-button-to-another-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!