簡體   English   中英

導航欄未顯示在TableView上方

[英]Navigation bar not showing over TableView

我無法解釋為什么此代碼無法正常工作。 出於某種原因,導航欄是半透明的,並且tableView的內容正在其上滾動。

這是按鈕的代碼

 let outlineViewController = OutlineTableviewController()
        outlineViewController.pdfOutlineRoot = pdfoutline
        outlineViewController.delegate = self

        let nav = UINavigationController(rootViewController: outlineViewController)
        self.present(nav, animated: true, completion:nil)

這是tableView的代碼

super.viewDidLoad()

    let newBackButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.plain, target: self, action: #selector(dismissView))

    self.navigationItem.rightBarButtonItem = newBackButton

    navigationController?.navigationBar.backgroundColor = UIColor(red:0.00, green:0.51, blue:0.78, alpha:1.0)


   self.tableView.dataSource = self
   self.tableView.delegate = self

   tableView?.register(UINib(nibName: "OutlineTableViewCell", bundle: nil),
                        forCellReuseIdentifier: "OutlineTableViewCell")
}

結果如下:不顯示背景色,表格位於導航欄下方。

我想念什么?

在此處輸入圖片說明

謝謝trungduc的回復。

在花了幾個小時試圖找出問題所在之后,我終於能夠通過更改根視圖中的顏色來解決此問題。

        let nav = UINavigationController(rootViewController: oulineViewController)
        nav.navigationBar.backgroundColor = UIColor(red:0.00, green:0.51, blue:0.78, alpha:1.0)
        self.present(nav, animated: true, completion:nil)

您在問題中提到了魔術字:“半透明”。

我遇到了同樣的問題:導航欄顯示在Storyboard的根視圖上,但是在運行Simulator時,視圖頂部沒有導航欄。 這解決了它:

導航控制器>導航欄>取消半透明(默認選中)。 這做了兩件事:

  1. 我的導航欄顯示在所有后續視圖中。
  2. 現在最頂層的子視圖(在您的情況下為表格視圖)位於Y = 0,而不是Y = 64。

在此處輸入圖片說明

暫無
暫無

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

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