------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------
UINavigationController大致的简介截图至一份朋友给的课件
(这个课件我问问看能不能分享出来,因为是他培训机构的课件,内容不多,但是概括性不错。)

然后我们看下例子要实现的简单看下效果

(不好意思,这个截图手抖了,有点难看。)
好了,现在说下大致步骤
1.首先还是创建一个工程
然后这边我们不用MainWindow.xib方式来实现布局了。
直接代码实现。
我们都知道在应用启动后要创建一个window啊什么的。然后window的根视图等等。这个一般是AppDelegate中完成
-
-
-
-
-
-
-
-
- #import "NonoAppDelegate.h"
- #import "NonoFirstLevelViewController.h"
- @implementation NonoAppDelegate
-
- @synthesize window = _window;
- @synthesize navController = _navController;
-
- - (void)dealloc
- {
- [_window release];
- [_navController release];
- [super dealloc];
- }
-
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
-
- self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
-
-
-
- UINavigationController *nc = [[UINavigationController alloc] init];
- self.navController = nc;
- [nc release];
- NonoFirstLevelViewController *tableVc = [[NonoFirstLevelViewController alloc] initWithNibName:@"NonoFirstLevelViewController" bundle:nil];
-
-
- [self.navController initWithRootViewController:tableVc];
- [tableVc release];
- self.window.rootViewController = self.navController;
- self.window.backgroundColor = [UIColor redColor];
- [self.window makeKeyAndVisible];
- return YES;
- }
视图放置顺序基本就是 window ——NavigationC——FirstLevelVC。
然后我们会看到蓝色的导航条上的标题,以及后面要涉及到的回退,操作按钮。
IOS开发中得操作习惯一开始还是很难适应的。
理论上来说对于蓝色框内(也就是导航条本身的设置),我们应该是获取navc对象本身来进行操作,但是貌似
熟悉了代码后,发现对于导航条上修改和设置是通过当前被展示得视图的视图控制去设置。
下面我们看下FirstLevel,也就是导航控制器中顶级视图实现类的部分代码
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.title = @"第一级视图";
-
-
-
- UIBarButtonItem *rigthButton = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:UIBarButtonItemStyleBordered target:self action:@selector(editButtonPressed:)];
- self.navigationItem.rightBarButtonItem = rigthButton;
- [rigthButton release];
-
- NSMutableArray *array = [[NSMutableArray alloc] init ];
- self.controllers = array;
- [array release];
- [self initAllSecondControllers:self.controllers];
-
-
-
-
-
-
-
- }
1》导航条的标题有两个方法,设置当前视图得title后,导航条会自动把其当做导航条的title,还有是获取当前视图的导航条控制器,设置title。
2》同理得设置左右按钮也是一样。
顶级视图是不能被pop的,一般呈现形式就是这样。
3.点击一个item后进入二级试图去看看。
整点击进入二级视图就是一个push入一个控制器视图
- NonoSecondLevelViewController *secondVC = [self.controllers objectAtIndex:row];
-
-
- [self.navigationController pushViewController:secondVC animated:YES];
默认的,进入二级视图后,导航条就会自动添加一个回退按钮,如果上级视图没有设置title,
按钮得默认文字是“back”,如果设置了title,文字就是这个title。
运用系统默认的样式实现navc基本就是这样,左右键和标题,也能符合我们简单得需求。
对于导航条的样式得修改
系统提供了4中样式

上图设置了bar的style:
//放在window上的根视图
UINavigationController *nc = [[UINavigationController alloc] init];
[nc.navigationBar setBarStyle:UIBarStyleBlackOpaque];
一个右边得button;
一个切换或是加载提示框类似于
self.navigationItem.prompt = @"加载";
在处理完逻辑后,设置成nil就ok了。
对于如何自定义导航条,这个下回等我熟透了代码在整。