模态与非模态进入和退出UIViewController以及UINavigationController简单用法
2014-04-27 18:25
190 查看
UIViewController有两个常用属性,一个控制导航显示内容,一个是自身导航控制器
@property(nonatomic,readonly,retain)UINavigationItem
*navigationItem;// Created on-demand so that a view controller may customize its navigation appearance.
@property(nonatomic,readonly,retain)UINavigationController
*navigationController;// If this view controller has been pushed onto a navigation controller, return it.
UINavigationItem的常用属性
@property(nonatomic,copy) NSString *title;
// Title when topmost on the stack. default is nil 导航视图控制器标题
@property(nonatomic,retain)UIBarButtonItem *leftBarButtonItem; // 左导航键
@property(nonatomic,retain)UIBarButtonItem *rightBarButtonItem; //右导航键
UIBarButtonItem常用构造方法
- (id)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action;
UINavigationController继承自UIViewController
一般用法是创建一个UINavigationController将UIViewController设置为它的根视图来显示
常用属性
@property(nonatomic,readonly)UINavigationBar *navigationBar;//
The navigation bar managed by the controller. Pushing, popping or setting navigation items on a managed navigation bar is not supported.
// 常常将它的属性 translucent 设置为NO来控制导航栏不透明,此时坐标原点移动到导航栏下方视图的左上角
UINavigationBar 常用属性
@property(nonatomic,assign,getter=isTranslucent)BOOL
translucent NS_AVAILABLE_IOS(3_0);// Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent
示例
AppDelegate.m中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]]autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColorwhiteColor];
FirstViewController * firstViewController = [[FirstViewControlleralloc]init];
UINavigationController * nav = [[UINavigationControlleralloc]initWithRootViewController:firstViewController];
[self.windowsetRootViewController:nav];
[self.windowmakeKeyAndVisible];
return YES;
}
FirstViewController.m中
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view.
//设置导航标题和导航右键
[self.navigationItemsetTitle:@"第一视图"];
[self.navigationController.navigationBarsetTranslucent:NO];//设置导航栏不透明
UIBarButtonItem * rightBarButtonItem = [[UIBarButtonItemalloc]initWithTitle:@"next"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(btnAction)];
[self.navigationItemsetRightBarButtonItem:rightBarButtonItem];
[rightBarButtonItem release];
//测试按钮
UIButton * btn = [[UIButtonalloc]initWithFrame:CGRectMake(60,200,200,50)];
[btn setBackgroundColor:[UIColorgrayColor]];
[btn setTitle:@"进入下一视图控制器" forState:UIControlStateNormal];
[btn addTarget:selfaction:@selector(btnAction)forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:btn];
[btn release];
}
-(void)btnAction
{
SecondViewController * secondViewController = [[SecondViewControlleralloc]init];
//模态进入
//UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:secondViewController];
//[self presentViewController:nav animated:NO completion:^{}];
//[secondViewController release];
//[nav release];
//非模态进入
[self.navigationControllerpushViewController:secondViewControlleranimated:NO];
[secondViewController release];
}
SecondViewController中
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view.
//设置导航标题和导航左键
[self.navigationItemsetTitle:@"第二视图"];
UIBarButtonItem * leftBarButtonItem = [[UIBarButtonItemalloc]initWithTitle:@"previous"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(btnAction)];
[self.navigationItemsetLeftBarButtonItem:leftBarButtonItem];
[leftBarButtonItem release];
//测试按钮事件
UIButton * btn = [[UIButtonalloc]initWithFrame:CGRectMake(60,200,200,50)];
[btn setBackgroundColor:[UIColorgreenColor]];
[btn setTitle:@"返回上一视图控制器" forState:UIControlStateNormal];
[btn addTarget:selfaction:@selector(btnAction)forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:btn];
[btn release];
}
-(void)btnAction
{
//模态返回
//[self dismissViewControllerAnimated:NO completion:^{}];
//非模态返回
[self.navigationControllerpopViewControllerAnimated:NO];
}
@property(nonatomic,readonly,retain)UINavigationItem
*navigationItem;// Created on-demand so that a view controller may customize its navigation appearance.
@property(nonatomic,readonly,retain)UINavigationController
*navigationController;// If this view controller has been pushed onto a navigation controller, return it.
UINavigationItem的常用属性
@property(nonatomic,copy) NSString *title;
// Title when topmost on the stack. default is nil 导航视图控制器标题
@property(nonatomic,retain)UIBarButtonItem *leftBarButtonItem; // 左导航键
@property(nonatomic,retain)UIBarButtonItem *rightBarButtonItem; //右导航键
UIBarButtonItem常用构造方法
- (id)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action;
UINavigationController继承自UIViewController
一般用法是创建一个UINavigationController将UIViewController设置为它的根视图来显示
常用属性
@property(nonatomic,readonly)UINavigationBar *navigationBar;//
The navigation bar managed by the controller. Pushing, popping or setting navigation items on a managed navigation bar is not supported.
// 常常将它的属性 translucent 设置为NO来控制导航栏不透明,此时坐标原点移动到导航栏下方视图的左上角
UINavigationBar 常用属性
@property(nonatomic,assign,getter=isTranslucent)BOOL
translucent NS_AVAILABLE_IOS(3_0);// Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent
示例
AppDelegate.m中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]]autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColorwhiteColor];
FirstViewController * firstViewController = [[FirstViewControlleralloc]init];
UINavigationController * nav = [[UINavigationControlleralloc]initWithRootViewController:firstViewController];
[self.windowsetRootViewController:nav];
[self.windowmakeKeyAndVisible];
return YES;
}
FirstViewController.m中
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view.
//设置导航标题和导航右键
[self.navigationItemsetTitle:@"第一视图"];
[self.navigationController.navigationBarsetTranslucent:NO];//设置导航栏不透明
UIBarButtonItem * rightBarButtonItem = [[UIBarButtonItemalloc]initWithTitle:@"next"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(btnAction)];
[self.navigationItemsetRightBarButtonItem:rightBarButtonItem];
[rightBarButtonItem release];
//测试按钮
UIButton * btn = [[UIButtonalloc]initWithFrame:CGRectMake(60,200,200,50)];
[btn setBackgroundColor:[UIColorgrayColor]];
[btn setTitle:@"进入下一视图控制器" forState:UIControlStateNormal];
[btn addTarget:selfaction:@selector(btnAction)forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:btn];
[btn release];
}
-(void)btnAction
{
SecondViewController * secondViewController = [[SecondViewControlleralloc]init];
//模态进入
//UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:secondViewController];
//[self presentViewController:nav animated:NO completion:^{}];
//[secondViewController release];
//[nav release];
//非模态进入
[self.navigationControllerpushViewController:secondViewControlleranimated:NO];
[secondViewController release];
}
SecondViewController中
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view.
//设置导航标题和导航左键
[self.navigationItemsetTitle:@"第二视图"];
UIBarButtonItem * leftBarButtonItem = [[UIBarButtonItemalloc]initWithTitle:@"previous"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(btnAction)];
[self.navigationItemsetLeftBarButtonItem:leftBarButtonItem];
[leftBarButtonItem release];
//测试按钮事件
UIButton * btn = [[UIButtonalloc]initWithFrame:CGRectMake(60,200,200,50)];
[btn setBackgroundColor:[UIColorgreenColor]];
[btn setTitle:@"返回上一视图控制器" forState:UIControlStateNormal];
[btn addTarget:selfaction:@selector(btnAction)forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:btn];
[btn release];
}
-(void)btnAction
{
//模态返回
//[self dismissViewControllerAnimated:NO completion:^{}];
//非模态返回
[self.navigationControllerpopViewControllerAnimated:NO];
}
相关文章推荐
- TinyXML类库和对象模型 以及简单的TinyXML的简单用法。
- fullpage的简单介绍以及用法
- CoordinatorLayout的使用,以及FloatingActionButton、snakebar的简单用法
- springMVC用法 以及一个简单的基于springMVC hibernate spring的配置
- unity3d射线的原理用法以及一个利用射线实现简单拾取的小例子
- Android 最简单动画实现(imageView,webview的进入和退出)
- iOS 横屏模态进入下一级界面, 竖屏退出
- 退出程序, intent.setFlags用法以及ActivityGroup相关--getLocalActivityManager()
- 动态获取程序的版本名称的方法以及dialog的简单用法以及两种上下文的区别
- 简单介绍HttpURLConnection请求网络以及AsyncTask异步任务的用法
- Android 支持网络协议以及简单用法
- 常用的正则表达表达式以及简单用法
- ng-include用法分析以及多标签页面的简单实现方式
- 常用的正则表达表达式以及简单用法
- FragmentTabHost简单用法,以及Fragment生命周期
- Android Studio添加volley以及volley的简单用法
- 窗口进入退出的 简单滑动动画效果
- framebuffer以及简单用法
- DBMS_LOB的简单用法以及释放DBMS_LOB生成的临时CLOB内存
- 【unity3d游戏开发之基础篇】unity3d射线的原理用法以及一个利用射线实现简单拾取的小例子