簡體   English   中英

未在TabBarController中嵌入的navigationBar中顯示按鈕項目

[英]Button item not shown in navigationBar embebed in TabBarController

我正在開發一個應用程序,其中viewController嵌入在navigationBar中,而這個navigationBar嵌入在TabBarViewController中。

在我的應用中,我有2個不同的標簽(目前),其中一個標簽是“活動視圖”。 這是一個帶有tableView的listController的viewController。 每個單元格都將顯示相同的視圖控制器,並在觸摸時顯示詳細信息活動。

我的問題是沒有顯示帶有按鈕的navigationItem。

我正在嘗試以下解決方案: 導航欄上未顯示Bar按鈕項 ,因為我的問題非常相似,但是沒有用。

故事板和應用程序運行的一些屏幕截圖: 故事板 應用程序在沒有按鈕的情況下運行

我正在嘗試以編程方式添加按鈕,但沒有結果:

var logoutButton: UIBarButtonItem!
var filterButton: UIBarButtonItem!


//MARK: - Lyfe cycle
override func viewDidLoad() {
super.viewDidLoad()

let logoutImage = UIImage(named: "logout-24")
let filterImage = UIImage(named: "filterOutline-24")

logoutButton = UIBarButtonItem(image: logoutImage, style: .Plain, target: self, action: "logoutAction:")
filterButton = UIBarButtonItem(image: filterImage, style: .Plain, target: self, action: "filterAction:")
navigationItem.rightBarButtonItems = [filterButton, logoutButton]

檢查您的圖像。 我看不到您的代碼有任何問題。 或者您可以嘗試僅添加如下標題

logoutButton = UIBarButtonItem(title: "Log out", style: .Plain, target: self, action:Selector("logoutAction:"))
filterButton = UIBarButtonItem(title: "Filter", style: .Plain, target: self, action: Selector("filterAction:"))

如果顯示按鈕欄。 我確定問題出在你的形象上。

我也遇到了類似的問題,后來我發現可以在選項卡欄控制器本身中設置導航欄,而無需在視圖控制器中進行設置

let profilePutton = UIButton(type: .custom)
profilePutton.setTitle("Profile", for: .normal)
profilePutton.frame = CGRect(x: 0.0, y: 0.0, width: 30.0, height: 30.0)
profilePutton.addTarget(self, action: #selector(openProfilePage), for: .touchUpInside)
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: profilePutton)

對於Tabar應用程序,我們應該這樣添加,

 let logoutButton = UIBarButtonItem(image: UIImage(named: "ic_logout"), style: .plain, target: self, action:#selector(logoutButtonTapped))    
 self.tabBarController?.navigationItem.leftBarButtonItem = logoutButton

 let nightModeButton = UIBarButtonItem(image: UIImage(named: "ic_night_mode_off"), style: .plain, target: self, action:#selector(nightModeButoonTapped))
 self.tabBarController?.navigationItem.rightBarButtonItem  = nightModeButton

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM