RootViewController中的UIToolbar [英] UIToolbar in RootViewController

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

问题描述

启动我的应用程序时,我需要 UIToolbar .它将贯穿整个应用程序的每个屏幕.为此,我将其添加到 RootViewController .

I need UIToolbar when my application launches. It will be on every screen through out the application. So for that i have add it in RootViewController.

#import "AppDelegate.h"
#import "MainViewController.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize mainViewController = _mainViewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
// Override point for customization after application launch.
self.mainViewController = [[[MainViewController alloc]init]autorelease];
self.window.rootViewController = self.mainViewController;
[self.window makeKeyAndVisible];
return YES;
}

当前我在MainViewController中有 UIToolbar

Currently i have UIToolbar in MainViewController

 // create the UIToolbar at the bottom of the MainViewController
toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlackOpaque;
// size up the toolbar and set its frame
toolbar.frame = CGRectMake(0, 425, 320, 40);
[self.view addSubview:toolbar];

在我所有其他的 UIViewControllers 中,我像这样添加它

In all my other UIViewControllers i m adding it like this

[self.view addSubview:toolbar]; 

我不想要的.我希望将 UIToolbar 附加到 rootviewcontroller 后,在其他所有 UIViewControllers 中自动显示.这样,当我翻转 UIViewController 更改为另一个 UIViewController 时.只有 UIViewController 不能翻转 UIToolbar .现在, UIToolbar 也可以通过 UIViewController 翻转.因此,这就是我要将其附加到 rootviewcontroller 的原因.

which i don't want. I want UIToolbar to show automatically in all my other UIViewControllers after attaching it to rootviewcontroller. so that when i flip UIViewController to change to another UIViewController. Only UIViewController should flip not UIToolbar.Right now UIToolbar is also flipping with UIViewController. So that is the reason i want to attach it to the rootviewcontroller.

所以我该如何在APPDelegate 文件中添加 UIToolbar并将其附加到 rootviewcontroller .

So how can i add UIToolbar in APPDelegate file and attach it to rootviewcontroller.

感谢您的帮助.

推荐答案

除了创建UIToolbar之外,一切在您的代码中看起来都不错,由于某种原因,您需要自己编写语法.这就是创建UIToolBar的方式

Everything looks okay in your code except when you create the UIToolbar, for some reason at that point you make your own syntax. This is how you create a UIToolBar

示例:

UIToolbar *toolBar = [UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44);

严重的是,您的代码将无法编译,并且您将确切地知道哪一行.连接点和Google如何创建UIToolbar.

Seriously, your code would not compile, and you would know at exactly what line. Connect the dots and Google how to create a UIToolbar.

对于在每个视图中显示的工具栏,您有几个选择:

For the Toolbar being display in every view you have a few options:

(1)确定要不要UINavigationController&UINavigationBar?

(1) Are you sure you don't want a UINavigationController & UINavigationBar?

(2)将其附加到UIWindow(即在窗口中添加两个子视图).这必须使用代码创建,我认为接口构建器无法正常工作.

(2) Attach it at the UIWindow (i.e. add two subviews to the window). This has to be created with code, I do not believe interface builder is going to work.

(3)只需在每个视图都以init或viewDidLoad方法加载时创建它

(3) Just create it when each view loads in either (init or viewDidLoad methods)

好的,因此您必须将工具栏添加到每个视图控制器(即addSubView).唯一的其他方法是将两个子视图添加到AppDelegate.

Okay, so you would have to add the Toolbar to each view controller (i.e. addSubView). The only other way is to add two subViews to the AppDelegate.

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

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