<small id='BrH4y'></small><noframes id='BrH4y'>

  1. <legend id='BrH4y'><style id='BrH4y'><dir id='BrH4y'><q id='BrH4y'></q></dir></style></legend>

      • <bdo id='BrH4y'></bdo><ul id='BrH4y'></ul>
    1. <i id='BrH4y'><tr id='BrH4y'><dt id='BrH4y'><q id='BrH4y'><span id='BrH4y'><b id='BrH4y'><form id='BrH4y'><ins id='BrH4y'></ins><ul id='BrH4y'></ul><sub id='BrH4y'></sub></form><legend id='BrH4y'></legend><bdo id='BrH4y'><pre id='BrH4y'><center id='BrH4y'></center></pre></bdo></b><th id='BrH4y'></th></span></q></dt></tr></i><div id='BrH4y'><tfoot id='BrH4y'></tfoot><dl id='BrH4y'><fieldset id='BrH4y'></fieldset></dl></div>
      <tfoot id='BrH4y'></tfoot>

      Swift 自定义后退按钮和目的地

      时间:2023-06-11
        <tbody id='3XFXt'></tbody>

    2. <small id='3XFXt'></small><noframes id='3XFXt'>

      <legend id='3XFXt'><style id='3XFXt'><dir id='3XFXt'><q id='3XFXt'></q></dir></style></legend>
    3. <i id='3XFXt'><tr id='3XFXt'><dt id='3XFXt'><q id='3XFXt'><span id='3XFXt'><b id='3XFXt'><form id='3XFXt'><ins id='3XFXt'></ins><ul id='3XFXt'></ul><sub id='3XFXt'></sub></form><legend id='3XFXt'></legend><bdo id='3XFXt'><pre id='3XFXt'><center id='3XFXt'></center></pre></bdo></b><th id='3XFXt'></th></span></q></dt></tr></i><div id='3XFXt'><tfoot id='3XFXt'></tfoot><dl id='3XFXt'><fieldset id='3XFXt'></fieldset></dl></div>

        <bdo id='3XFXt'></bdo><ul id='3XFXt'></ul>
        <tfoot id='3XFXt'></tfoot>

                本文介绍了Swift 自定义后退按钮和目的地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我目前在我的应用程序中使用 SWRevealViewController 作为侧边栏菜单.当我单击其中一个选项时,目标视图控制器没有返回"按钮,因为它不是来自正确的视图控制器(即要返回的页面).

                I am currently using SWRevealViewController for a sidebar menu in my app. When I click one of the options, the destination view controller doesn't have a 'back' button because it hasn't come from a proper view controller (i.e. page to go back to).

                因此,我想在目标视图控制器上手动创建一个返回按钮,该按钮将返回到主视图控制器.

                Therefore I am wanting to manually create a back button on the destination view controller which will go back to the home view controller.

                我在这里查看了代码:如何手动设置返回"?iOS 应用中的目的地

                但我正在努力在 Swift 中实现这一点(一个又一个错误!).有什么帮助吗?谢谢!

                But I am struggling to implement this in Swift (one error after another!). Any help? Thanks!

                编辑

                我已经尝试了下面的建议,但是后退按钮没有出现.这可能与我将导航栏隐藏在其他视图中并在目标视图中执行以下操作有关:

                I have tried the suggestion below, but the back button just doesn't appear. This may have something to with the fact I have the navbar hidden in other views and do the following on the destination view:

                override func viewDidLoad() {
                    super.viewDidLoad()
                    navigationController.setNavigationBarHidden(false, animated:true)
                    var myBackButton:UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
                    myBackButton.addTarget(self, action: "popToRoot:", forControlEvents: UIControlEvents.TouchUpInside)
                
                    var myCustomBackButtonItem:UIBarButtonItem = UIBarButtonItem(customView: myBackButton)
                    self.navigationItem.leftBarButtonItem = myCustomBackButtonItem
                }
                
                override func didReceiveMemoryWarning() {
                    super.didReceiveMemoryWarning()
                }
                
                func popToRoot(sender:UIBarButtonItem){
                    self.navigationController.popToRootViewControllerAnimated(true)
                }
                

                不确定为什么后退按钮不显示?

                Not sure why the back button won't show up?

                编辑

                这是来自我的侧边栏视图控制器的 prepareForSegue.如果有办法检查 segue 标识符test",那么我可以从这里设置后退按钮?

                This is the prepareForSegue from my sidebar view controller. If there is a way to check for the segue identifier 'test' then I can set the back button from here?

                - (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
                {
                // Set the title of navigation bar by using the menu items
                NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
                UINavigationController *destViewController = (UINavigationController*)segue.destinationViewController;
                destViewController.title = [[_menuItems objectAtIndex:indexPath.row] capitalizedString];
                
                
                if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] ) {
                    SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;
                
                    swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {
                
                        UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
                        [navController setViewControllers: @[dvc] animated: NO ];
                        [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
                    };
                
                }
                
                }
                

                推荐答案

                你可以这样用swift写

                You can write that in swift like this

                编写此代码以在 navigationController

                    navigationController.setNavigationBarHidden(false, animated:true)
                    var myBackButton:UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
                    myBackButton.addTarget(self, action: "popToRoot:", forControlEvents: UIControlEvents.TouchUpInside)
                    myBackButton.setTitle("YOUR TITLE", forState: UIControlState.Normal)
                    myBackButton.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal)
                    myBackButton.sizeToFit()
                    var myCustomBackButtonItem:UIBarButtonItem = UIBarButtonItem(customView: myBackButton)
                     self.navigationItem.leftBarButtonItem  = myCustomBackButtonItem
                

                这将弹出到 rootViewController

                    func popToRoot(sender:UIBarButtonItem){
                       self.navigationController.popToRootViewControllerAnimated(true)
                    }
                

                这篇关于Swift 自定义后退按钮和目的地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:UINavigationController:每次转换后显示具有不同方向的嵌入式视图控制器? 下一篇:没有导航控制器的 pushViewController

                相关文章

                1. <i id='l6dZc'><tr id='l6dZc'><dt id='l6dZc'><q id='l6dZc'><span id='l6dZc'><b id='l6dZc'><form id='l6dZc'><ins id='l6dZc'></ins><ul id='l6dZc'></ul><sub id='l6dZc'></sub></form><legend id='l6dZc'></legend><bdo id='l6dZc'><pre id='l6dZc'><center id='l6dZc'></center></pre></bdo></b><th id='l6dZc'></th></span></q></dt></tr></i><div id='l6dZc'><tfoot id='l6dZc'></tfoot><dl id='l6dZc'><fieldset id='l6dZc'></fieldset></dl></div>
                    <bdo id='l6dZc'></bdo><ul id='l6dZc'></ul>

                  <small id='l6dZc'></small><noframes id='l6dZc'>

                  1. <tfoot id='l6dZc'></tfoot>

                  2. <legend id='l6dZc'><style id='l6dZc'><dir id='l6dZc'><q id='l6dZc'></q></dir></style></legend>