/*

 

 

 

 程序过程:

 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颜色设置为红色。



                **总结



     1,从第一层向第二层正向传參时:
          在第二层页面中创建一个接收这个參数的属性
          在第一层向第二层跳转时 创建完第二层的实例对象,

 */



<SendValue.h>
#import
<Foundation/Foundation.h>



@protocol
SendValue <NSObject]]>

- (void)sendBtnTitle:(NSString*)title;

@end





<XSAppDelegate.m>


#import
"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.m>

#import
"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];

}






<XSSecondViewController.h>

#import
<UIKit/UIKit.h>

#import "SendValue.h"



@interface
XSSecondViewController : UIViewController

//定义代理

@property
(nonatomic,assign)id<SendValue>
delegate;

//创建一个正向传值的属性,

@property
(nonatomic,copy)NSString*currentTitle;

@end



<XSSecondViewController.m>

#import
"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 传统的价值观,代理传统价值观,正向传统价值观,反传统的价值观的更多相关文章

  1. Mybatis系列全解(七):全息视角看Dao层两种实现方式之传统方式与代理方式

    封面:洛小汐 作者:潘潘 一直以来 他们都说为了生活 便追求所谓成功 顶级薪水.名牌包包 还有学区房 · 不过 总有人丢了生活 仍一无所获 · 我比较随遇而安 有些事懒得明白 平日里问心无愧 感兴趣的 ...

  2. iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem

    http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...

  3. [转]iOS学习之UINavigationController详解与使用(三)ToolBar

    转载地址:http://blog.csdn.net/totogo2010/article/details/7682641 iOS学习之UINavigationController详解与使用(二)页面切 ...

  4. iOS视图控制对象生命周期

    iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...

  5. [转]iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController

    转载地址:http://blog.csdn.net/totogo2010/article/details/7682433 iOS学习之UINavigationController详解与使用(一)添加U ...

  6. IOS 视图控制对象生命周期-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear等的区别及用途

    iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...

  7. Visual Studio跨平台开发实战(2) - Xamarin.iOS基本控制项介绍

    原文 Visual Studio跨平台开发实战(2) - Xamarin.iOS基本控制项介绍 前言 在上一篇文章中, 我们介绍了Xamarin 以及简单的HelloWorld范例, 这次我们针对iO ...

  8. iOS学习之UINavigationController详解与使用(三)ToolBar

    1.显示Toolbar  在RootViewController.m的- (void)viewDidLoad方法中添加代码,这样Toobar就显示出来了. [cpp] view plaincopy [ ...

  9. iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController

    iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem是上篇,我们接着讲UINavigationController的重要作用,页面的管理和切换. ...

  10. 【iOS系列】-UINavigationController的使用(Segue传递数据)

    [iOS系列]-UINavigationController的使用 UINavigationController是以以栈(先进后出)的形式保存子控制器, 常用属性: UINavigationItem有 ...

随机推荐

  1. 字符串如何判断null.

    转http://blog.sina.com.cn/s/blog_48cd37140101awgq.html Java中判断String不为空的问题 一.判断一个字符串str不为空的方法有: 1. st ...

  2. php前端控制器2

    Front Controllers act like centralized agents in an application whose primary area of concern is to ...

  3. MySQL分组数据

    分组 理解分组能够看例如以下一个样例,首先我们打印出products表例如以下 从上面的表中能够看出.每一个vendor都有若干个产品,那么怎么一次统计每一个vendor有多少个产品呢? 这里就能够使 ...

  4. POJ1700(过河问题)

    #include<iostream> #include<algorithm> using namespace std; ]; int main() { int t,i; cin ...

  5. BZOJ 4145: [AMPPZ2014]The Prices( 状压dp + 01背包 )

    我自己只能想出O( n*3^m )的做法....肯定会T O( nm*2^m )做法: dp( x, s ) 表示考虑了前 x 个商店, 已买的东西的集合为s. 考虑转移 : 先假设我们到第x个商店去 ...

  6. uoj Goodbye Jiawu

    这次比赛真是太伤我心了. 比(惨)赛(不)结(忍)果(睹) 完挂感言 uoj round 5已经挂了一次了,没想到还要再挂第二次. 这次比赛的期望得分是\(100+100+100+70+10\)的.没 ...

  7. 不可表示的数[x/2] + y + x * y

    前端是时间在庞果网上看到不可表示的数的编程题(如下),我自己也试着解答了一下,写的算法虽然没有没有错,但是跑了一些还只是跑到a8,后来到自己整理一下网上的解答过程,虽然解答写的很清晰,但是有些知识还是 ...

  8. Spring注入静态变量(转)

    今天碰到一个问题,我的一个工具类提供了几种静态方法,静态方法需要另外一个类的实例提供处理,因此就写出了这样的代码: Class Util{ private static XXX xxx; xxx = ...

  9. inner join、left join、right join中where和and的作用

    inner join.left join.right join中where和and的作用 .内连接(自然连接): 只有两个表相匹配的行才能在结果集中出现 2.外连接: 包括  (1)左外连接 (左边的 ...

  10. Java学习笔记九(泛型)

    1.介绍 所谓的泛型就是将类型作为一种參数来传递.有了泛型后类型不再是一成不变的.能够通过泛型參数来指定. 能够提供程序开发的灵活性. 2.泛型类或接口的使用 泛型类声明时.与普通类没有太大的差别,仅 ...