1.新建一个single view工程:
2.在AppDelegate.m中
MyUIViewController *vc1 = [[MyUIViewController alloc] init];
vc1.title = @"vc1";
vc1.view.backgroundColor = [UIColor grayColor];
UINavigationController *nc1 = [[UINavigationController alloc] initWithRootViewController:vc1];
[vc1 release];
UIViewController *vc2 = [[UIViewController alloc] init];
vc2.title = @"vc2";
vc2.view.backgroundColor = [UIColor redColor];
UINavigationController *nc2 = [[UINavigationController alloc] initWithRootViewController:vc2];
[vc2 release];
UIViewController *vc3 = [[UIViewController alloc] init];
vc3.title = @"vc3";
vc3.view.backgroundColor = [UIColor purpleColor];
UINavigationController *nc3 = [[UINavigationController alloc] initWithRootViewController:vc3];
[vc3 release];
UIViewController *vc4 = [[UIViewController alloc] init];
vc4.title = @"vc4";
vc4.view.backgroundColor = [UIColor greenColor];
UINavigationController *nc4 = [[UINavigationController alloc] initWithRootViewController:vc4];
[vc4 release];
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = [NSArray arrayWithObjects:nc1, nc2, nc3, nc4, nil];
self.window.rootViewController = tbc;
[tbc release];
[nc1 release];
[nc2 release];
[nc3 release];
[nc4 release];
效果如图
在MyViewController中添加
- (void)btnClick
{
SecondViewController *svc = [[SecondViewController alloc] init];
svc.view.backgroundColor = [UIColor whiteColor];
svc.title = @"second";
[self.navigationController pushViewController:svc animated:YES];
[svc release];
}
效果如图
点next按钮,效果如图
如果希望底部的tabbar在跳转至后消失,可以在
[self.navigationController pushViewController:svc animated:YES];
之前添加
self.hidesBottomBarWhenPushed = YES;
这样跳转至后就没有底部的tabbar了,但是点左上的vc1按钮返回到第一个界面的时候发现底部的tabbar仍然不在,所以需要添加如下代码,使其返回的时候会弹出tabbar
- (void) viewDidDisappear:(BOOL)animated
{
self.hidesBottomBarWhenPushed = NO;
}