UINavigationItem titleView “ignored if leftBarButt

2019-01-18 23:36发布

The documentation for UINavigationItem's titleView property says: "This property is ignored if leftBarButtonItem is not nil."

However, I've set both the titleView and leftBarButtonItem properties in my testing and they both appear to show up fine. I've tested on all the simulators in my Xcode: 4.3, 5.0, and 5.1. Does anyone know if the documentation is just wrong, or is it correct on some older versions (e.g. 4.2, 3.x) that I haven't been able to test?

5条回答
Rolldiameter
2楼-- · 2019-01-18 23:42

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

查看更多
该账号已被封号
3楼-- · 2019-01-18 23:47

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

查看更多
Summer. ? 凉城
4楼-- · 2019-01-18 23:49

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.

查看更多
三岁会撩人
5楼-- · 2019-01-18 23:52

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.

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-01-19 00:01

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.

查看更多
登录 后发表回答