iPhone开发笔记[8/50]:选项卡栏编程的关键步骤

1. 使用Window-Based Application模板新建一个工程,例如名称是ttt
2. 添加UIViewController
  从classes中添加新文件,选UIViewController模板(根据情况可以选中UITableViewController),要建立相应的.h和.xib文件,这样会建立出aaaViewController.m, aaaViewController.h, aaaViewController.xib三个文件
  xib的文件名中包含有controller这个单词不太舒服,将aaaViewController.xib重命名为aaaView.xib
  总共有几个选项卡,就得重复几个这样的步骤
3. 将应用程序代理做为选项卡控制器的代理
  (1)修改tttAppDelegate.h
  在@interface那一行中的"<UIApplicationDelegate"后插入", UITabBarControllerDelegate"。这个操作有点疑问,看了另外一本书,竟然没有这一步,不知道是什么原因。
  在"UIWindow *window;“后插入一行
  IBOutlet UITabBarController *tabBarController;
  在@end前加一行
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
  (2)修改tttAppDelegate.m
  在application:didFinishLaunchingWithOptions:方法中加入下面一行
[window addSubView:tabBarController.view];
  在dealloc方法中最前面插入一行
[tabBarController release];

4. 在MainWindow.xib中加入一个UITabBarController
  拖拽一个UITabBarController(不是UITabBar)到MainWindow.xib的文档窗口中
  按住ctrl键,拖住tttAppDelegate图标与Tab Bar Controller的输出口tabBarController关联起来

5. 如果选项卡不够用,就在Tab Bar Controller的检查器中多加几个选项卡
6. 设置选项卡的标题和图像,设置时要选中Tab Bar Item
7. 用Command+4将MainWindow.xib中的ViewController与aaaViewControll类关联起来

  用Command+1再将该ViewController与aaaView.xib界面关联起来

  有几个选项卡就得重复几次这样的操作

-------------------------------------------------------------------------------------------------------------

 

  作者:毒龙的程序人生{speeding}http://www.cnblogs.com/speeding/
  版权声明:本文的版权归作者和博客园共有,转载时须注明本文的详细链接,否则作者将保留追究其法律责任。

posted @ 2011-07-11 16:15  申龙斌的程序人生  阅读(1100)  评论(0编辑  收藏  举报