如何在标签栏viewcontroller中显示后退按钮?

时间:2017-08-04 09:38:35

标签: ios swift uinavigationcontroller uitabbarcontroller

我的导航控制器的根目录有一个家庭视图控制器。然后我推一个标签栏视图控制器。后退按钮消失。如何通过后退按钮从标签栏视图控制器返回到主视图控制器?我怎样才能再次看到它?

我试过了:

let navItem = self.navigationController?.navigationItem
let navItem2 = self.navigationItem;
leftBarButton = UIBarButtonItem()
leftBarButton.image = UIImage(named: "arrows-back-icon-24.png")
leftBarButton.action = #selector(self.popViewController);
leftBarButton.target = self
navItem?.leftBarButtonItem = leftBarButton
navItem2.leftBarButtonItem = leftBarButton;

我也尝试过:

let navItem = self.navigationController?.navigationItem
let navItem2 = self.navigationItem;
navItem?.leftBarButtonItem = nil;
navItem2.leftBarButtonItem = nil;

一切都行不通。请帮忙。感谢。

3 个答案:

答案 0 :(得分:1)

试试这个:将UITabBarController类文件分配给Tab Bar Controller,就像视图控制器一样。

import UIKit
//this is TabBarController.swift file
class TabBarController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()

    }
}

enter image description here

从HomeVC推送它(这里,我使用UIButton for Push):

@IBAction func btnPush(_ sender: UIButton) {
    let vc = self.storyboard?.instantiateViewController(withIdentifier: "TabBarController") as! TabBarController
    self.navigationController?.pushViewController(vc, animated: true)
}

答案 1 :(得分:0)

我遇到了同样的问题,但就我而言,这是由于viewWillAppear方法引起的。尝试将以下内容添加到相应UITabBarController中嵌入的每个UIViewController中:

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        self.navigationController?.setNavigationBarHidden(false, animated: true)
    }

希望这对您有用。

答案 2 :(得分:-1)

private static void FillDefaultSimpleScheduleBuilder(SimpleScheduleBuilder inputBuilder, int interval, int? repeatCount)
    {
        var builder = inputBuilder.WithIntervalInSeconds(interval);
        builder = repeatCount.HasValue ? builder.WithRepeatCount(repeatCount.Value) : builder.RepeatForever();

        // fire once immediately if misfire occurs.
        builder.WithMisfireHandlingInstructionNowWithExistingCount();
    }

试试这个