导航控制器UINavigationController控制一系列的UIViewController,他们组成一个层次结构,每一个ViewController都在这个层次结构中上下移动,组织方式是栈形式。
每个UIViewController都有相关联的UINavigationItem,后者处于活动状态时将位于UINavigationBar中,每个UINavigationItem都可能包含一个或多个UIBarButtonItem,让导航栏能包括其他操作项。
一般情况下,导航控制器结构包含四个对象:
一个UINavigationController;
一个UINavigationBar;
一个UIViewController;
一个UINavigationItem(放在UINavigationBar中)
下面来创建一个导航控制器:
首先建立一个Empty project,在AppDelegate.h中声明并在m文件中实现:
@property (strong,nonatomic)UINavigationController *navController;
然后建一个RootViewController继承UITableViewController作为导航控制器的根视图
然后建立MovieViewController来作为RootViewController条目的子视图
在RootViewController里面添加方法:
(void)viewDidLoad { [superviewDidLoad]; self.title = @"类别"; NSMutableArray *array = [[NSMutableArrayalloc]init]; MovieController *movieController = [[MovieControlleralloc]initWithStyle:UITableViewStylePlain]; movieController.title = @"电影"; [array addObject:movieController]; self.controllerList = array;
由于继承了UITableViewController,所以要实现必要的方法,这里列出关键代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { staticNSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell... NSUInteger row = [indexPath row]; UITableViewController *controller = [self.controllerListobjectAtIndex:row]; cell.textLabel.text = controller.title; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; }
这是单击条目后进入子视图的方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger row = [indexPath row]; UITableViewController *detailController = [self.controllerListobjectAtIndex:row]; //进入下一个视图的操作 [self.navigationControllerpushViewController:detailController animated:YES]; [detailController release];
这样基本实现了导航控制的目的,导航栏上方的返回按钮是根据前一个视图的标题自动生成的。
另外还有一些操作是为导航栏添加左右按钮,
self.navigationItem.rightBarButtonItem = [UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItem addTarget:self : action:@selector(change)];
定义顶部左右按钮的方式有如下几种:
initWithBarButtonSystem:target:action: :创建一个标准按钮
initWithCustomView: 自定义按钮(view)
initWithImage:style:target:action 创建一个带图片的按钮
initWithTitle:style:target:action 创建一个带标题的按钮
相关推荐
我们写iOS项目的时候,基本都是一个UINavigationController套一个UITabBarController的形式,就是上面一个导航栏,下面几个按钮的工具条的形式。我写了几个应用,发现如果每次都重新写的话完全就是浪费精力和时间,...
上传的demo关于UINavigationController中back按钮的重写方法, UINavigationController的back按妞本身是没有监听方法的,但是我们通过添加类目可以使back按钮具有监听的作用.让我们能在UINavigationController触发返回...
IOS7 UINavigationController滑动Demo,解决了在push后的页面可以滑动返回的问题。
页面跳转 UITabBarController+UINavigationController+UIViewController
导航控制器(UINavigationController)用来管理一系列显示层次型信息的场景。一般而言,逐步显示更详细的信息。 导航控制器 -- 用户在场景之间切换时,导航控制器依次将视图控制器压入(push)堆栈中,且当前场景的...
* 从iOS7开始,系统为UINavigationController提供了一个interactivePopGestureRecognizer用于右滑返回(pop),但是,如果自定了返回按钮或者隐藏了navigationBar,该手势就失效了。 ## 原因 * 自定义返回按钮或者隐藏...
UITabBarController和UINavigationController的整合使用DEMO,详情见:http://blog.csdn.net/hwe_xc/article/details/50588500
让 UINavigationController 支持全屏操作手势.zip,A UINavigationController's category to enable fullscreen pop gesture with iOS7 system style.
很多时候我们创建一个基于UITabBarController的application以后还希望能够在每个tab view都可以实现导航控制,即添加一个UINavigationController来实现tabview内部的view之间的切换,这即是本文所要介绍的。
iOS 使用UINavigationController 进行页面跳转 http://blog.csdn.net/liuyan20092009/article/details/52233769
自定义UITabBar,layoutSubviews重写UITabBarButton位置,重写则hitTest方法并监听按钮的点击 自定义的UITabBarController和UINavigationController
iphone中的基础控件UINavigationController,适合初学者,主要学习UINavigationController的基本属性和常用方法调用。 UINavigationController也是一种常用的容器,跟前边学过的tabbar差不多,在这个容器中可以添加...
UINavigationController 简单使用方法,增加自定义导航按钮。图片按钮,switch按钮。
iOS UINavigationController自定义,push动画效果
UInavigationController笔记
一个小demo,演示如何隐藏tabbar
相关知识共享: leftBarButtonItem与backBarButtonItem的区别 - http://blog.csdn.net/moon_prince2013/article/details/49079251 ViewController中[self setTtile]与[self.navigationItem setTitle]的... ... ...
NULL 博文链接:https://android-zhang.iteye.com/blog/1756555