iOS基本控制-UINavigationController 传统的价值观,代理传统价值观,正向传统价值观,反传统的价值观
/*
程序过程:
1。创建一个根视图,一个二级视图
2,根视图NavigationItem.title = Root 二级视图NavigationItem.title
= Second
根视图NavigationItem.rightButton入栈二级视图
3,
二级视图中创建三个buttonbutton一 button二 button三
三个button点击时间都是出栈。并把自己的button的
titel 赋给根视图的NavigationItem.title
4。当再次进入二级视图时,推断根视图的NavigationItem.title和哪个button的title一样。假设
一样。就把button的title颜色设置为红色。
*/
<Foundation/Foundation.h>
@protocol
SendValue <NSObject]]>
- (void)sendBtnTitle:(NSString*)title;
@end
"XSAppDelegate.h"
#import "XSRootViewController.h"
@implementation XSAppDelegate
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
self.window= [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];
// Override point for customization after application launch.
self.window.backgroundColor=
[UIColorwhiteColor];
XSRootViewController*rootViewController = [[XSRootViewControlleralloc]init];
UINavigationController*navController = [[UINavigationControlleralloc]initWithRootViewController:rootViewController];
self.window.rootViewController=
navController;
[self.windowmakeKeyAndVisible];
return
YES;
}
"XSRootViewController.h"
#import "XSSecondViewController.h"
@interface XSRootViewController()
@end
@implementationXSRootViewController
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self
= [super
initWithNibName:nibNameOrNil
bundle:nibBundleOrNil];
if
(self) {
// Custom initialization
}
return
self;
}
- (void)viewDidLoad
{
[super
viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=
[UIColoryellowColor];
self.navigationItem.title=
@"Root";
UIBarButtonItem*btnItem = [[UIBarButtonItemalloc]initWithTitle:@"Push"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(btnClick:)];
self.navigationItem.rightBarButtonItem=
btnItem;
}
//#pragma mark --SendVaule
- (void)sendBtnTitle:(NSString*)title
{
self.navigationItem.title=
title;
}
- (void)btnClick:(UIBarButtonItem*)btnItem
{
XSSecondViewController*secondViewController = [[XSSecondViewControlleralloc]init];
secondViewController.delegate=
self;
secondViewController.currentTitle=
self.navigationItem.title;
[self.navigationControllerpushViewController:secondViewControlleranimated:YES];
}
<UIKit/UIKit.h>
#import "SendValue.h"
@interface
XSSecondViewController : UIViewController
//定义代理
@property
(nonatomic,assign)id<SendValue>
delegate;
//创建一个正向传值的属性,
@property
(nonatomic,copy)NSString*currentTitle;
@end
"XSSecondViewController.h"
#import "XSRootViewController.h"
@interface XSSecondViewController()
@end
@implementationXSSecondViewController
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self
= [super
initWithNibName:nibNameOrNil
bundle:nibBundleOrNil];
if
(self) {
// Custom initialization
}
return
self;
}
- (void)viewDidLoad
{
[super
viewDidLoad];
// Do any additional setup after loading the view.
UIBarButtonItem*btnItem = [[UIBarButtonItemalloc]initWithTitle:@"Pop"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(btnClick)];
self.navigationItem.leftBarButtonItem=
btnItem;
self.view.backgroundColor=
[UIColorblueColor];
UIButton*btn1 = [UIButtonbuttonWithType:UIButtonTypeSystem];
btn1.frame=
CGRectMake(10, 80, 300, 40);
[btn1 setTitle:@"按键一"forState:UIControlStateNormal];
[btn1 setBackgroundColor:[UIColorwhiteColor]];
[btn1 addTarget:selfaction:@selector(btnClick:)forControlEvents:UIControlEventTouchUpInside];
btn1.tag= 1;
//假设button的标题和属性中的_currentTitle同样,即和根页面中的导航条的title一样
if
([_currentTitleisEqualToString:btn1.currentTitle])
{
btn1.selected=
YES;
}
//假设selected为YES就运行setTitleColor
[btn1 setTitleColor:[UIColorredColor]forState:UIControlStateSelected];
[self.viewaddSubview:btn1];
UIButton*btn2 = [UIButtonbuttonWithType:UIButtonTypeSystem];
btn2.frame=
CGRectMake(10, 130, 300, 40);
[btn2 setTitle:@"按键二"forState:UIControlStateNormal];
[btn2 setBackgroundColor:[UIColorwhiteColor]];
[btn2 addTarget:selfaction:@selector(btnClick:)forControlEvents:UIControlEventTouchUpInside];
btn2.tag= 2;
//假设button的标题和属性中的_currentTitle同样,即和根页面中的导航条的title一样
if
([_currentTitleisEqualToString:btn2.currentTitle])
{
btn2.selected=
YES;
}
//假设selected为YES就运行setTitleColor
[btn2 setTitleColor:[UIColorredColor]forState:UIControlStateSelected];
[self.viewaddSubview:btn2];
UIButton*btn3 = [UIButtonbuttonWithType:UIButtonTypeSystem];
btn3.frame=
CGRectMake(10, 180, 300, 40);
[btn3 setTitle:@"按键三"forState:UIControlStateNormal];
[btn3 setBackgroundColor:[UIColorwhiteColor]];
[btn3 addTarget:selfaction:@selector(btnClick:)forControlEvents:UIControlEventTouchUpInside];
btn3.tag= 3;
//假设button的标题和属性中的_currentTitle同样,即和根页面中的导航条的title一样
if
([_currentTitleisEqualToString:btn3.currentTitle])
{
btn3.selected=
YES;
}
//假设selected为YES就运行setTitleColor
[btn3 setTitleColor:[UIColorredColor]forState:UIControlStateSelected];
[self.viewaddSubview:btn3];
}
- (void)btnClick
{
[self.navigationControllerpopToRootViewControllerAnimated:YES];
}
- (void)btnClick:(UIButton*)btn
{
//取出button的标题
NSString*title = btn.currentTitle;
//推断代理中是否有sendBtnTitle:这个函数
if
([_delegate
respondsToSelector:@selector(sendBtnTitle:)]) {
//代理运行自己的sendBtnTitle函数,传參是title
[_delegatesendBtnTitle:title];
}
[self.navigationControllerpopToRootViewControllerAnimated:YES];
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
iOS基本控制-UINavigationController 传统的价值观,代理传统价值观,正向传统价值观,反传统的价值观的更多相关文章
- Mybatis系列全解(七):全息视角看Dao层两种实现方式之传统方式与代理方式
封面:洛小汐 作者:潘潘 一直以来 他们都说为了生活 便追求所谓成功 顶级薪水.名牌包包 还有学区房 · 不过 总有人丢了生活 仍一无所获 · 我比较随遇而安 有些事懒得明白 平日里问心无愧 感兴趣的 ...
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...
- [转]iOS学习之UINavigationController详解与使用(三)ToolBar
转载地址:http://blog.csdn.net/totogo2010/article/details/7682641 iOS学习之UINavigationController详解与使用(二)页面切 ...
- iOS视图控制对象生命周期
iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...
- [转]iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController
转载地址:http://blog.csdn.net/totogo2010/article/details/7682433 iOS学习之UINavigationController详解与使用(一)添加U ...
- IOS 视图控制对象生命周期-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear等的区别及用途
iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...
- Visual Studio跨平台开发实战(2) - Xamarin.iOS基本控制项介绍
原文 Visual Studio跨平台开发实战(2) - Xamarin.iOS基本控制项介绍 前言 在上一篇文章中, 我们介绍了Xamarin 以及简单的HelloWorld范例, 这次我们针对iO ...
- iOS学习之UINavigationController详解与使用(三)ToolBar
1.显示Toolbar 在RootViewController.m的- (void)viewDidLoad方法中添加代码,这样Toobar就显示出来了. [cpp] view plaincopy [ ...
- iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController
iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem是上篇,我们接着讲UINavigationController的重要作用,页面的管理和切换. ...
- 【iOS系列】-UINavigationController的使用(Segue传递数据)
[iOS系列]-UINavigationController的使用 UINavigationController是以以栈(先进后出)的形式保存子控制器, 常用属性: UINavigationItem有 ...
随机推荐
- javaScript 网页特效 输出语句
大家好,我是小强老师,今天主要讲解 三个最为常用的输出语句. alert() 弹出警示框 window.alert(‘继续学习’); 完整的写法 效果如下: 因为alert 属于window 对象 ...
- go - 变量和常量
1.定义变量 goLang中定义变量的方式很多 先声明再使用:如果定义的变量未使用编译时会报错 a. /*定义单个变量*/ var varName type //定义一个 type 类型的变量 var ...
- C#如何在panl控件上添加Form窗体
. if (treeView1.SelectedNode.Text == "个人信息") { Form1 f4 = new Form1(); f4.TopLevel = false ...
- 解析stm32的时钟
STM32 时钟系统 http://blog.chinaunix.net/uid-24219701-id-4081961.html STM32的时钟系统 *** http://www.cnblo ...
- VS2010 ,工程文件减肥
写一个bat文件来清理VS2010工程文件. 将其放入到工程文件夹下,双击即可自动将sdf,ipch等占用空间很大的文件删除. 这样的方式较之于转移浏览数据库文件的位置而言更为灵活一些,不用特别的设置 ...
- Step by step guide to set up master and slave machines(转)
Note: There is no need to install Jenkins on the slave machine. On your master machine go to Manage ...
- 求 n! (大数问题)----------HDOJ1042
以下只YY算法,c++实现,java大神绕道..... (1)位数的估计 显然对于大数(比如1000的阶乘)的阶乘我们找不到一个数据类型存放这个数,是在太大啦.... 那么现在来估计一 ...
- 【SICP感应】3
级数据和符号数据
在本书的第二章学习时,有一个问题我一直很困扰,那是2.2.4举例节.因为没有华丽的输出模式书,它只能有一个对的英文字母.两三个月的这浅浅的学校前Common Lisp同样是真实的,当.了非常赞的线条, ...
- 恢复PasswordChar 默认值、取消密码框设置
//三种都是清空 this.textBox1.PasswordChar = new char(); this.textBox1.PasswordChar = '\0'; this.textBox1.P ...
- Taxonomy of class loader problems encountered when using Jakarta Commons Logging(转)
Acknowledgments I would like to thank Jacob Kjome for reviewing early drafts of this document. His c ...