简体   繁体   中英

Set NavigationBar title on next ViewController without visual bugs

So I have a UICollectionView called WeatherVC that has a NavigationController .

WeatherVC segues to WeatherDetailVC which is UITableView upon UICollectionViewCell selection.

I want to set WeatherDetailVC NavigationBar title based on which UICollectionViewCell was selected.

This code below makes my whole NavigationBar just buggy. Example: https://imgur.com/a/vOIbxK5

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let vc = segue.destination as? WeatherDetailVC {
      let cities = ["City1", "City2", "City3", "City4"]
      // cellPressed = 3 - for example this would work without bugs
      vc.navigationItem.title = cities[cellPressed]
    }
}

Variable cellPressed was set on cell highlight or tap. It behaves like this only in iOS 13 and only if I give it number based on cell tapped - if it is static, title changes with no visual bugs. I already tried creating functions inside WeatherDetailVC to change its title and calling them in prepare for:segue but it did not help whatsoever.

EDIT: My main problem is those bugs or glitches that comes with this solution. I have no problem with changing next VC title.

Since navigationBar title represents the title of the view controller, You can set it directly:

vc.title = cities[cellPressed]

Assuming cities[cellPressed] is tested and returning correct value

I figured it out. It happens because of the diacritic. If I assign title with diacritic character navigation bar just bugs everytime. Anyone know how to fix it?

EDIT: You can see this happening in IMGUR link that I provided. Character "á" is in the title.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM