2017-08-04 77 views
0

我有一個導航控制器的根目錄控制器。然後我推一個標籤欄視圖控制器。後退按鈕消失。如何通過後退按鈕將標籤欄視圖控制器返回到主視圖控制器?我怎樣才能讓它再次可見?如何在選項卡視圖控制器中顯示返回按鈕?

我曾嘗試:

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; 

所有不工作。請幫忙。謝謝。

+0

你需要做'tabBarViewController'爲'rootViewController' –

+1

是你這樣的流量? UINavigationController - > UIViewController(你的主vc) - > UITabBarController。 –

+0

嘗試更改爲leftBarButton.action = #selector(self.navigationController?.popViewController)。但首先你需要確認工作流UINavigationController - > UIViewController(Home) - > UITabBarController – wskcoder

回答

-1
let btn1 = UIButton(type: .custom) 
btn1.setImage(UIImage(named: "image"), for: .normal) 
btn1.frame = CGRect(x: 0, y: 0, width: 20, height: 20) 
btn1.addTarget(self, action: #selector(methodname), for: .touchUpInside) 
let item1 = UIBarButtonItem(customView: btn1) 

let btn2 = UIButton(type: .custom) 
btn2.setImage(UIImage(named: "image"), for: .normal) 
btn2.frame = CGRect(x: 0, y: 0, width: 20, height: 20) 
btn2.addTarget(self, action: #selector(methodName), for: .touchUpInside) 
let item2 = UIBarButtonItem(customView: btn2) 

self.navigationItem.setLeftBarButtonItems([item1,item2], animated: true) 

試試這個

+0

問題不在於按鈕的內容。問題在於,無論我設置在TabBar上的左欄按鈕項目中,它都是空的。 –

1

試試這個:分配的UITabBarController類文件標籤欄控制器,就像視圖控制器。

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

    } 
} 

enter image description here

而且從HomeVC這樣推(在這裏,我使用的UIButton推送):

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