UINavigationController大致的简介截图至一份朋友给的课件
(这个课件我问问看能不能分享出来,因为是他培训机构的课件,内容不多,但是概括性不错。)
然后我们看下例子要实现的简单看下效果
(不好意思,这个截图手抖了,有点难看。)
好了,现在说下大致步骤
1.首先还是创建一个工程
然后这边我们不用MainWindow.xib方式来实现布局了。
直接代码实现。
我们都知道在应用启动后要创建一个window啊什么的。然后window的根视图等等。这个一般是AppDelegate中完成
//
// NonoAppDelegate.m
// NavTest
//
// Created by Nono on 12-4-26.
// Copyright (c) 2012年 NonoWithLilith. All rights reserved.
//
#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
{
//应用的第一层是个window
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
//放在window上的根视图
UINavigationController *nc = [[UINavigationController alloc] init];
self.navController = nc;
[nc release];
NonoFirstLevelViewController *tableVc = [[NonoFirstLevelViewController alloc] initWithNibName:@"NonoFirstLevelViewController" bundle:nil];
//将First作为控制器的顶级视图。
[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 = @"第一级视图";
// self.navigationItem.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];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
1》导航条的标题有两个方法,设置当前视图得title后,导航条会自动把其当做导航条的title,还有是获取当前视图的导航条控制器,设置title。
2》同理得设置左右按钮也是一样。
顶级视图是不能被pop的,一般呈现形式就是这样。
3.点击一个item后进入二级试图去看看。
整点击进入二级视图就是一个push入一个控制器视图
NonoSecondLevelViewController *secondVC = [self.controllers objectAtIndex:row];
// ...
// Pass the selected object to the new view controller.
[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了。
对于如何自定义导航条,这个下回等我熟透了代码在整。
分享到:
相关推荐
包含collectionView,UIBezierPath,ActionSheet,DatePicker,pickerView,SearchBar,UIActivityIndicatorView,UIAlertView,UIButton,UIimagePicker,UILabel,UInavigationController,UIProgressView,UIScrollerView,...
当一个项目发现每个返回的按钮都是一样的,并且标题的字体也不是系统的字体,如果每个页面都去设置返回按钮,重新设置标题字体,这样代码...UINavigationController *vc = [[UINavigationController alloc] init]; f
包含常用的控件的使用UILabel、UIButton、UIsegmentedControl、UITextField、UISlider、UISwitch、UIActivityIndicatorView、UIProgressView、UIStepper、UIImageView、UIAlertView、UIActionSheep、UIDatePicker、...
UINavigationController HXSuspend是UINavigationController的分类,悬浮窗相关的处理逻辑都在这里。 HXCircleTransition是自定义转场动画类 HXSuspendWindow悬浮窗的视图,继承自UIWindow HXCircularSectorView...
//超出这个view的边界的控件不再显示 [_infoView setClipsToBounds:YES]; //UIView 静态方法,开始一个动画 [UIView beginAnimations:nil context:nil]; begin 开始 //animation 动画 duration 间隔时间 ...
swift-badge, 在 Swift 中,为 ios/tvos编写的徽章视图 和tvOS用 Swift 编写的徽章控件 徽章是UILabel视图的子类。可以从 Storyboard 或者从代码中创建和定制它。设置有三种方法可以将BadgeSwift添加到Xcode项目中。...
该源码案例是一款不错的导航选项的菜单控件,源码DOPNavbarMenu,一款增加导航选项的控件,相信很多同学可能会用到。 使用方法: 复制DOPNavbarMenu文件夹即可使用: 属性方法: @property (copy, nonatomic, ...
DL汉堡包菜单DLHamburguerMenu是一个完全以迅捷方式编写的“汉堡包”侧边栏菜单控件。 它在当前视觉内容(即:当前UINavigationController上方)上显示一个菜单。 使用情节提要进行集成很容易。 适用于iOS 7+结构...
做了这么长时间的ios开发了,最基本的UITabBarController和UINavigationController都用了好长时间了,总是改现成的代码,或者各种自定义控件的修改,用的都有些混乱了,呵呵。还是自己做个demo再复习一下吧,记录...
作者CEWendel,源码SWNavigationController,SWNavigationController 是一个 UINavigationController 子类,可以点击边缘左右滑动来切换视图层。
使用 MFSideMenu 实现类似 Facebook...示例往左滑动到自定义表格视图,往右滑动到省市列表视图,另外涉及到 UINavigationController 及 UIBarButtonItem控件的使用。 本示例代码结构清晰,注释详尽,有助于初学者入门。
该文件简单实现了iOS下通讯录功能,使用XCode编辑,iPhone6调试,主要使用了UINavigationController,UITableView……等基本控件, 很适合初学者。
源码STPopup,像使用 UINavigationController 一样使用你的弹窗。 STPopupController *popupController = [[STPopupController alloc] initWithRootViewController:[ViewController new]]; [popupController ...
UINavigationController (导航控制器) – 压栈出栈管理视图 模态窗口 二、UITabBarController分页控制器 UITabBarController是为了利用 页签切换视图 设计的控制器 该控制器有一个UITabBar控件,用户通过点击...
作者dasdom,源码DDHCustomTransition,DDHCustomTransition 是一个帮助类,能使基本的视图控件更加容易转换。创建一个 NavigationControllerDelegate 的实例,并设置为一个 UINavigationController 的委托属性。使...
Composable 的灵感来自 iOS 的视图和功能组合模式。 我们希望能够将各种级别的显示样式和功能封装为组件(例如按钮),然后以声明方式将它们包含在其他视图中,例如 Interface Builder。 我们希望能够推送和弹出视图...