UINavigationItem titleView “ignored if leftBarButtonItem is set”?

早过忘川 提交于 2019-11-28 11:02:53
indisoluble

Check the documentation for property leftBarButtonItems, it says:

If there is not enough room to display all of the items in the array, those that would overlap the title view (if present) or the buttons on the right side of the bar are not displayed.

So, what's said for titleView is probably incorrect.

I think the documentation is wrong, and you should file a bug report.

I tested this on iOS6.1 and iOS7. My UINavigationItem had a non-nil titleView and leftBarButtonItem, and both the titleView and leftBarButtonItem were visible. I filed a radar.

I've run into this as well. In My specific problem both the titleview and leftbar item would appear. However If I had a Back Button then my titleview would disappear on Push and use the default title. If I have a custom uibuttonitem set for the left it works fine. So It seems to be related to back button. I ended up solving by setting title attributes and no doing a custom view.

I just ran into this and found the same thing you did. I also noted that the documentation for UINavigationItem was last updated in 2011, while UINavigationBar got updates in both iOS 5 and 6, so it's possible this behavior changed since the last time the UINavigationItem doc was updated.

Very confusing though.

Noticed this as well in UINavigationController's reference:

"The navigation controller updates the middle of the navigation bar as follows:

...

If the new top-level view controller has a custom title view, the navigation bar displays that view in place of the default title view. To specify a custom title view, set the titleView property of the view controller’s navigation item."

Since there's a leftBarByButton (the back button) by definition anytime you're at the non-root view, it sure seems like a mistake in the UINavigationItem's documentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!