UIToolbar中的持久UIBarButtonItem? [英] Persistent UIBarButtonItem in UIToolbar?

查看:146
本文介绍了UIToolbar中的持久UIBarButtonItem?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个使用UIToolbar的iPhone应用程序(在UINavigationController的上下文中),在屏幕底部显示一个小状态图标。工具栏最终还会有与之关联的动作图标(想想邮件应用程序)。

I've been developing an iPhone app that uses a UIToolbar (in the context of a UINavigationController) to display a small status icon at the bottom of the screen. The toolbar will eventually also have action icons associated with it (think Mail application).

我遇到一个问题,看起来每个UIViewController都推到导航控制器上堆栈应该有自己的一组项目供工具栏显示,因此,状态项目淡出并重新进入每个视图转换。

I'm running into an issue where it appears that each UIViewController pushed onto the navigation controller's stack is expected to have its own set of items for the toolbar to display, and as a result, the "status" item fades out and back in for each view transition.

有没有办法在工具栏中有一个持久性项目?我也尝试在导航控制器的初始化程序中添加项目(我为此方法分类了UINavigationController),但它仍然没有。

Is there a way to have a single persistent item in the toolbar? I also tried adding the item in the navigation controller's initializer (I subclassed UINavigationController for this approach), but it's still no go.

推荐答案

不使用导航控制器的工具栏,而是直接在窗口中添加一个,并调整导航控制器视图框架的大小以避免它。然后,该单个全局工具栏将始终可见。

Instead of using the navigation controller's toolbar, add one directly to the window and resize the navigation controller's view's frame to avoid it. That single global toolbar will then always be visible.

如果您正在使用基于导航的应用程序模板,并且正在使用Interface Builder,则以下步骤应该这样做:

If you're using the Navigation-based Application template, and are using Interface Builder, the following steps should do it:


  1. 打开你的app delegate的.h文件。

  2. 添加一个 IBOutlet UIToolbar *工具栏; 到app delegate的实例变量。

  3. 切换到.m文件。

  4. 找到读取 [window addSubview:[navigationController view]]; 的行并在其后添加:
    CGRect frame = navigationController.view.frame;
    frame.size.height - = toolbar.frame.size.height;
    navigationController.view.frame = frame;

  5. 在<中添加代码以释放工具栏 code> -dealloc 方法。

  6. 打开MainWindow.xib。

  7. 打开窗口。

  8. 将工具栏拖到窗口底部。

  9. 将工具栏连接到应用程序委托工具栏

  10. 现在设置工具栏 - 添加您需要的任何项目,然后在应用程序委托中创建所需的任何插座和操作并连接它们。

  1. Open up your app delegate's .h file.
  2. Add an IBOutlet UIToolbar * toolbar; to the app delegate's instance variables.
  3. Switch to the .m file.
  4. Find the line that reads [window addSubview:[navigationController view]]; and add after it:
    CGRect frame = navigationController.view.frame;
    frame.size.height -= toolbar.frame.size.height;
    navigationController.view.frame = frame;
  5. Add code to release toolbar in the -dealloc method.
  6. Open MainWindow.xib.
  7. Open the window.
  8. Drag a toolbar onto the bottom of the window.
  9. Connect the toolbar to the app delegate's toolbar outlet
  10. Now set up the toolbar—add whatever items you need to it, then create whatever outlets and actions you need in the app delegate and connect them.

由于工具栏是窗口的一部分,而不是导航控制器的一部分,导航控制器不应触摸它。

Since the toolbar is part of the window, not part of the navigation controller, the navigation controller shouldn't touch it.

这篇关于UIToolbar中的持久UIBarButtonItem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆