在开始之前,首先做一个程序的框架:
1.用UITabBarController+UINavigationController制作一个原生态的程序框架
@interface AppDelegate : UIResponder <</span>UIApplicationDelegate>{
UITabBarController *tabBarController;
UINavigationController*navSquareController;
UINavigationController*navMoreController;
UINavigationController*navSelfInfoController;
UINavigationController*navShootController;
UINavigationController*navVideoController;
}
@property (nonatomic,retain) UIWindow *window;
@property (strong, retain) UITabBarController *tabBarController;
@property (strong, retain) UINavigationController*navSquareController;
@property (strong, retain) UINavigationController*navMoreController;
@property (strong, retain) UINavigationController*navSelfInfoController;
@property (strong, retain) UINavigationController*navShootController;
@property (strong, retain) UINavigationController*navVideoController;
@end
-(BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window= [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// 广场
SquareViewController *squareViewController=[[SquareViewControlleralloc] initWithNibName:@"SquareViewController" bundle:nil];
navSquareController=[[UINavigationController alloc] initWithRootViewController:squareViewController];
// 设置广场-TabBar
UITabBarItem *itemSquare= [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:0];
squareViewController.tabBarItem=itemSquare;
[itemSquare release];
[squareViewControllerrelease];
// 视频
VideoViewController *videoViewController=[[VideoViewControlleralloc] initWithNibName:@"VideoViewController" bundle:nil];
navVideoController=[[UINavigationController alloc] initWithRootViewController:videoViewController];
// 设置视频-TabBar
UITabBarItem *itemVideo= [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavoritestag:0];
videoViewController.tabBarItem=itemVideo;
[itemVideo release];
[videoViewControllerrelease];
// 播放器
ShootViewController *shootViewController=[[ShootViewControlleralloc] initWithNibName:@"ShootViewController" bundle:nil];
navShootController=[[UINavigationController alloc] initWithRootViewController:shootViewController];
// 设置播放器-TabBar
UITabBarItem *itemShoot= [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostRecenttag:0];
shootViewController.tabBarItem=itemShoot;
[itemShoot release];
[shootViewControllerrelease];
// 会员信息
SelfInfoViewController *selfInfoViewController=[[SelfInfoViewControlleralloc] initWithNibName:@"SelfInfoViewController" bundle:nil];
navSelfInfoController=[[UINavigationController alloc] initWithRootViewController:selfInfoViewController];
// 设置会员-TabBar
UITabBarItem *itemInfo= [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:0];
selfInfoViewController.tabBarItem=itemInfo;
[itemInfo release];
[selfInfoViewControllerrelease];
// 更多
MoreViewController *moreViewController=[[MoreViewControlleralloc] init];
navMoreController=[[UINavigationController alloc] initWithRootViewController:moreViewController];
// 设置更多-TabBar
UITabBarItem *itemMore= [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMore tag:0];
moreViewController.tabBarItem=itemMore;
[itemMore release];
[moreViewControllerrelease];
// 加入tabBarController
self.tabBarController = [[[UITabBarController alloc] init]autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navSquareController,navVideoController,navShootController,navSelfInfoController,navMoreController, nil];
self.window.rootViewController = self.tabBarController;
[self.window addSubview:tabBarController.view];
[self.windowmakeKeyAndVisible];
return YES;
}
这个是原生态的一个框架。可以来做应用程序的公用框架!
我们的程序一般都是这样!经典啊!
运行如下:
于是,要问:为什么第一个页面要显示navSquareController?
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navSquareController,navVideoController,navShootController,navSelfInfoController,navMoreController, nil];
我们将navSquareController排在数组第一个元素,所以,默认显示navSquareController
为什么navSquareController又显示的是squareViewController?
navSquareController=[[UINavigationController alloc] initWithRootViewController:squareViewController];
squareViewController作为navSquareController的根视图控制器!
因为我们还没有对navSquareController进行任何pushViewController操作,所以,默认显示的是squareViewController。