4

I have a navigation bar which includes a search bar to filter the table data in current VC, let's call it 1st VC.

And the steps is active this search bar and cancel it. Then click any row of tableView 1st VC to open 2nd VC. The weird behavior is coming, the navigation title of 2nd VC is overlapped with 1st VC's nav title. Also the button on top-right is not clickable anymore after this issue happened. I get this when upgrade to iOS 13 from previous version 12.

/ / / attach the issue screenshot firstly, you could see that title "Music" in 1st VC is overlapped with title "Playing" in 2nd VC.

enter image description here

/ / / nav bar code in 1st VC

override func viewDidLoad() {
        super.viewDidLoad()

        // set tableView's separatorColor
        self.tableView.separatorColor = UIColor(rgb: 0x5E5E5E)

        // get songs from app's local dir
        self.retrieveSongsfromLocalDir()

        // add search bar
        resultSearchController = ({
            let controller = UISearchController(searchResultsController: nil)
            controller.searchResultsUpdater = self
            controller.hidesNavigationBarDuringPresentation = false
            controller.obscuresBackgroundDuringPresentation = false
            controller.searchBar.sizeToFit()
            // set search Bar covered color, same with tableView's background color.
            controller.searchBar.barTintColor = UIColor(rgb: 0x292f33)

            return controller
            })() // closure, learn it later!!

        navigationItem.searchController = resultSearchController

        // reload the tableView
        self.tableView.reloadData()

    }

/ / / I put the custom code of navigation bar in AppDelegate.swift for global use.

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Custom Navigation Bar's appearance.
        UINavigationBar.appearance().tintColor = UIColor.white
        UINavigationBar.appearance().barTintColor = UIColor(rgb: 0x55acee)
        UINavigationBar.appearance().isTranslucent = false
        UINavigationBar.appearance().clipsToBounds = false
        // UINavigationBar.appearance().backgroundColor
        UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.white, .font: UIFont.boldSystemFont(ofSize: 23)]
        return true
    }

/ / / Update, it is duplicate with thread https://stackoverflow.com/questions/58134631/ios-13-uibarbuttonitem-not-clickable-and-overlapping-uinavigationbars-when-using. It seems the bug of Apple from iOS 13, and temporary fix is to set hidesNavigationBarDuringPresentation = true.

Zhou Haibo
  • 1,681
  • 1
  • 12
  • 32

0 Answers0