这时刚刚进如app的视图效果。
这时是push视图后,返回后的效果。代码如下: ContactViewController *contactViewController = [[ContactViewController alloc] initWithNibName:@"ContactViewController" bundle:nil];
SMSViewController *SmsViewController = [[SMSViewController alloc] initWithNibName:@"SMSViewController" bundle:nil];
SettingViewController *settingViewController = [[SettingViewController alloc] initWithNibName:@"SettingViewController" bundle:nil];
ExpandViewController *expandViewController = [[ExpandViewController alloc] initWithNibName:@"ExpandViewController" bundle:nil];
NSArray *viewItemArray = [[NSArray alloc] initWithObjects:contactViewController, SmsViewController, expandViewController, settingViewController, nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate = self;
self.tabBarController.viewControllers = viewItemArray;
[[self.tabBarController.tabBar.items objectAtIndex:0] setTitle:@"Contact"];
[[self.tabBarController.tabBar.items objectAtIndex:1] setTitle:@"SMS"];
[[self.tabBarController.tabBar.items objectAtIndex:2] setTitle:@"Expand"];
[[self.tabBarController.tabBar.items objectAtIndex:3] setTitle:@"Setting"];
CGRect frame = CGRectMake(0, 0, 320, 48);
UIView *v = [[UIView alloc]initWithFrame:frame];
[v setBackgroundColor:[UIColor brownColor]];
[[self.tabBarController.tabBar.subviews objectAtIndex:0] removeFromSuperview];
[self.tabBarController.tabBar insertSubview:v atIndex:0];
[v release];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.tabBarController];
CGRect frames = CGRectMake(0, 0, 320, 48);
UIView *vw = [[UIView alloc]initWithFrame:frames];
[vw setBackgroundColor:[UIColor brownColor]];
[[nav.navigationBar.subviews objectAtIndex:0] removeFromSuperview];
[nav.navigationBar insertSubview:vw atIndex:0];
[vw release]; self.window.rootViewController = nav;
[nav release];
// self.window.rootViewController = self.mainViewController;
[self.window makeKeyAndVisible];
tab controller包含 nav controller包含 view controller
而你刚好相反
[nav setNavigationBarHidden:YES];
[nav setNavigationBarHidden:NO];