Changing navigation title programmatically

后端 未结 14 2238
长情又很酷
长情又很酷 2020-11-28 19:34

I have a navigation bar with a title. When I double click the text to rename it, it actually says it\'s a navigation item, so it might be that.

I\'m trying to change

14条回答
  •  生来不讨喜
    2020-11-28 19:58

    Normally, the best-practice is to set the title on the UIViewController. By doing this, the UINavigationItem is also set. Generally, this is better than programmatically allocating and initializing a UINavigationBar that's not linked to anything.

    You miss out on some of the benefits and functionality that the UINavigationBar was designed for. Here is a link to the documentation that may help you. It discusses the different properties you can set on the actual bar and on a UINavigationItem.

    Just keep in mind:

    1. You lose back button functionality (unless you wire it yourself)
    2. The built-in "drag from the left-hand side to swipe back" gesture is forfeited

    UINavigationController's are your friends.

提交回复
热议问题