将实用程序应用程序(2个视图控制器)转换为标签栏应用程序 [英] Converting an Utility application (2 view controllers) to a Tab bar Application

查看:54
本文介绍了将实用程序应用程序(2个视图控制器)转换为标签栏应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所示,我已经构建了一个基于实用程序的应用程序.
该应用程序(目前)由2个视图控制器+一个模型类层次结构组成.
事实是,正如我想向应用程序添加一些功能一样,我想将其转换为基于TabBar的应用程序.

As the title suggests, I have built an utility based app.
The app consists (at the moment) of 2 view controllers + a model class hierarchy.
The thing is , as I'd like to add some features to the app , I would like to convert it to a TabBar based application.

第一步,我希望第一个视图成为选项卡栏的第一个视图,而flipSideView成为其他选项卡栏项之一.

As a first step , I would like the first view to be the first view of the tab bar , and the flipSideView to be one of the other tab bar items.

此类任务是否有标准程序"/杂货清单"?
我确定你们中的一些人也遇到了同样的问题,并且希望在为主窗口创建一个新的nib文件之后切片"应用程序并接线"一些建议(这是第一步吗?)

Is there any "standard procedure" / "grocery list" for such tasks ?
I'm sure some of you have encountered the same problem , and would love some advice on "slicing up" the app , and "wiring it up" after creating a new nib file for the main window (is that the first step ? )

先谢谢了.

推荐答案

我可能会开始如下操作(假设您正在使用Interface Builder并使用标准的Xcode实用程序应用模板):

I would probably start as follows (assuming you are using Interface Builder and using the standard Xcode utility app template):

  • 编辑MainWindow.xib文件并将标签栏控制器"对象拖到视图层次结构的顶层.
  • IB中的默认选项卡栏控制器包括两个视图控制器项作为示例.单击第一个,并将其类更改为您现有的Main View Controller类.
  • 您还可以通过添加IB已经添加到视图层次结构中的关联的Tab Bar Item,来为主视图控制器项设置图标和Tab Bar标题.
  • 对第二个选项卡栏项目执行相同的操作,以设置FlipsideViewController的类.
  • 从NIB文件中删除主视图控制器的旧版本,并从应用程序代理中删除IBOutlet属性(您可能在dealloc中也有对主视图控制器的引用,应将其删除).
  • 在您的应用程序委托中,为标签栏控制器添加IBOutlet属性,如下所示(不要忘记合成该属性):

  • Edit your MainWindow.xib file and drag a Tab Bar Controller object into the top level of your view hierarchy.
  • The default tab bar controller in IB includes two view controller items as examples. Click the first one and change its class to be your existing Main View Controller class.
  • You can also set the icon and tab bar title for the main view controller item by adding the associated Tab Bar Item that IB has already added to the view hierarchy.
  • Do the same for the second tab bar item setting the class for the FlipsideViewController.
  • Delete the old version of your Main View Controller from the NIB file and also remove the IBOutlet property from the Application Delegate (you probably also have references to the main view controller in dealloc which should be removed).
  • In your App Delegate add an IBOutlet property for the Tab Bar Controller as follows (don't forget to synthesise the property):

@属性(非原子性,保留)IBOutlet UITabBarController * tabBarController;

@property (nonatomic,retain) IBOutlet UITabBarController *tabBarController;

在IB中,将tabBarController插座从App委托对象连接到Tab Bar Controller对象.

In IB wire up the tabBarController outlet from the App delegate object to the Tab Bar Controller object.

最后要显示标签栏控制器来代替主视图控制器,将application:didFinishLaunchingWithOptions:中的代码更改为以下内容:

Finally to get the tab bar controller to show up in place of the main view controller change the code in application:didFinishLaunchingWithOptions: to the following:

[self.window addSubview:self.tabBarController.view];

[self.window addSubview:self.tabBarController.view];

这应该可以启动并运行基本的标签栏应用,并且您可以将其他视图控制器添加到标签栏.

This should get the basic tab bar app up and running and you can add additional view controllers to the tab bar.

由于您不再希望在MainView和FlipsideView之间切换,因此可以从MainViewController中删除对FlipsideViewControllerDelegate的引用以及信息按钮及其IBAction方法showInfo.同样,在FlipeSideViewController中,应该从视图及其IBAction方法中删除完成按钮,因为当与标签栏一起使用时,这些按钮不再有意义.

Since you no longer want to flip between the MainView and FlipsideView you can remove the references to the FlipsideViewControllerDelegate from the MainViewController along with the info button and its IBAction method showInfo. Likewise in the FlipeSideViewController you should remove the done button from the view and its IBAction method as these no longer make sense when used with the tab bar.

这篇关于将实用程序应用程序(2个视图控制器)转换为标签栏应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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