iOS 4 中消失的 UIBarButtonItems

发布于 2025-01-08 12:53:00 字数 1334 浏览 3 评论 0原文

我一直在 iOS 5 设备上进行开发,并且运行良好。现在我已经使用不同版本的 iOS 模拟器对其进行了测试,在 4.0 中,我的自定义 UIBarButtonItems 出现了一些奇怪的行为。在应用程序的主屏幕上,两个栏按钮都会在应用程序的整个生命周期中显示。这两个按钮会弹出模态视图控制器,每个控制器都有一个“关闭”按钮。这是模态视图控制器之一上“关闭”按钮的对象描述(我在“viewWillAppear”方法中设置了一个断点):

(gdb) po [[[self navigationItem] rightBarButtonItem] customView]
<UIButton: 0x72766e0; frame = (264 6; 51 31); opaque = NO; layer = <CALayer: 0x7276d70>>

当打开每个模态视图控制器时,它们都会显示。但是,其中一个模式视图控制器有一个按钮,可以将另一个视图控制器推到顶部,并且视图控制器的基类自动创建一个自定义后退按钮并将其放在视图的 leftBarButtonItem 上。然而,这并没有显示出来。这是未显示的按钮的对象描述(再次在“viewWillAppear”中):

(gdb) po [[[self navigationItem] leftBarButtonItem] customView]
<UIButton: 0x766be00; frame = (0 0; 43 31); opaque = NO; layer = <CALayer: 0x766be90>>

...看起来没有任何问题。然后,我按下后退按钮应该在的位置,视图控制器弹出,显示第一个模态视图控制器,但没有“关闭”按钮。再次,我打破了 viewWillAppear,这就是我得到的:

(gdb) po [[[self navigationItem] rightBarButtonItem] customView]
<UIButton: 0x72766e0; frame = (264 6; 51 31); alpha = 0; opaque = NO; layer = <CALayer: 0x7276d70>>

这很奇怪,因为我没有在自己的代码中的任何地方设置 UIBarButtonItem 的 alpha 值。另外,它在 iOS 5 上工作得很好。我实现自定义 UIBarButtonItems 的方法是使用一些静态方法,我放入一个名为 UIBarButtonItem+Utils.h 的类别中,该方法返回使用自定义 UIButton 作为自定义视图初始化的 UIBarButtonItems。如果您需要我发布该方法的代码,我可以,但要点是它永远不会更改按钮的 alpha 值。还有其他人经历过类似的事情吗?

I've been developing on an iOS 5 device, and it's been working fine. Now I've been testing it with different versions of the iOS simulator, and in 4.0 I'm getting some strange behaviour with my custom UIBarButtonItems. On the main screen of the app both of the bar buttons show throughout the lifetime of the app. Those two buttons bring up modal view controllers, each with a 'close' button. This is an object description of the 'close' button on one of the modal view controllers (I set a breakpoint in the 'viewWillAppear' method):

(gdb) po [[[self navigationItem] rightBarButtonItem] customView]
<UIButton: 0x72766e0; frame = (264 6; 51 31); opaque = NO; layer = <CALayer: 0x7276d70>>

Those both show up when the each modal view controller is opened. But then one of the modal view controllers has a button that pushes another view controller on top, and the view controller's base class automatically makes a custom back button and puts it on the leftBarButtonItem of the view. However, this doesn't show up. Here's the object description of the button that doesn't show up (again, in 'viewWillAppear'):

(gdb) po [[[self navigationItem] leftBarButtonItem] customView]
<UIButton: 0x766be00; frame = (0 0; 43 31); opaque = NO; layer = <CALayer: 0x766be90>>

...which doesn't look like anything is wrong. I then press where the back button should be, and the view controller pops off, revealing the first modal view controller, but with no 'close' button. Again, I broke in viewWillAppear and this is what I got:

(gdb) po [[[self navigationItem] rightBarButtonItem] customView]
<UIButton: 0x72766e0; frame = (264 6; 51 31); alpha = 0; opaque = NO; layer = <CALayer: 0x7276d70>>

This is strange, since I don't set the alpha value of a UIBarButtonItem anywhere in my own code. Also, it works fine on iOS 5. The way I implement the custom UIBarButtonItems is using some static methods I put in a category called UIBarButtonItem+Utils.h that returns UIBarButtonItems initialised with a custom UIButton as the custom view. If you need me to post the code for that method I can, but the main point is that it doesn't ever change the button's alpha value. Has anyone else experienced anything like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文