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

**总结

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];

}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

时间: 2024-11-03 22:18:27

iOS基本控制-UINavigationController 传统的价值观,代理传统价值观,正向传统价值观,反传统的价值观的相关文章

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

1.RootView 跳到SecondView 首先我们需要新一个View.新建SecondView,按住Command键然后按N,弹出新建页面,我们新建SecondView 2.为Button 添加点击事件,实现跳转 在RootViewController.xib中和RootViewController.h文件建立连接 在RootViewController.m中实现代码,alloc一个SecondViewController,用pushViewController到navigationCon

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

1.显示Toolbar  在RootViewController.m的- (void)viewDidLoad方法中添加代码,这样Toobar就显示出来了. [cpp] view plaincopyprint? [self.navigationController  setToolbarHidden:NO animated:YES]; [self.navigationController setToolbarHidden:NO animated:YES]; 2.在ToolBar上添加UIBarBu

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

iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 init-初始化程序 viewDidLoad-加载视图 viewWillAppear-UIViewController对象的视图即将加入窗口时调用: viewDidApper-UIViewController对象的视图已经加入到窗口时调用: viewWillDisappear-UIViewCont

ios导航控制器UINavigationController,控制器a跳转(push)到b后,b跳转(push)到c,但c后退(pop)进入a

参考:StackOverflow ios导航控制器UINavigationController,控制器a跳转(push)到b后,b跳转(push)到c,但c后退(pop)进入a.在b跳转(push)到c中代码书写如下: UINavigationController *navController = [[self.navigationController retain] autorelease]; [navController popViewControllerAnimated:NO]; View

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

转载地址:http://blog.csdn.net/totogo2010/article/details/7682433 iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem是上篇,我们接着讲UINavigationController的重要作用,页面的管理和切换. 1.RootView 跳到SecondView 首先我们需要新一个View.新建SecondView,按住Command键然后按N,弹出新建页面,我们新建SecondView 2

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

转载地址:http://blog.csdn.net/totogo2010/article/details/7682641 iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController 接上篇,我们接着讲Navigation 的Toolbar. 1.显示Toolbar  在RootViewController.m的- (void)viewDidLoad方法中添加代码,这样Toobar就显示出来了. [cpp] view plaincopy

[转]iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem

转载地址:http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigationController可以翻译为导航控制器,在iOS里经常用到. 我们看看它的如何使用: 下面的图显示了导航控制器的流程.最左侧是根视图,当用户点击其中的General项时 ,General视图会滑入屏幕:当用户继续点击Auto-Lock项时,Auto-Lock视图将滑入屏幕.相应地,在

iOS开发之UINavigationController的使用

这一篇记录的是iOS开发中UINavigationController的使用,UINavigation即导航栏,主要是用于页面间的导航切换,本篇要实现的就是利用导航栏,在UITableView中点击一个单元格,然后跳转到详情页面,并且详情页面可以返回.效果图如下: 下面就一步步实现这个项目吧: 1.新建工程NavigationControllerTest 2.打开Main.storyboard文件,并选中其中的ViewController,然后在菜单中选择Editor-->Embed in-->

iOS 在使用UINavigationController和TabBarController时view的frame

可能是以前记错了,总认为在ios6上使用了UINavigationController或者TabBarController会因为多了bar而影响子controller的view的frame大小.今天在xcode5.1上验证,无论ios6或者7,使用容器controller,产生了的bar都不会对子controller的view的frame产生影响. 我们看看一个简单例子: 首先,可以看出,frame高度是568,没有收到bar的影响.其次Under top bars和under bottom b

ios开发:UINavigationController反方向滑动push

新建个UINavigationController的类别: #import "UINavigationController+CustomAnimation.h" @implementation UINavigationController (CustomAnimation) - (void)customPushViewController:(UIViewController *)viewController { viewController.view.frame = (CGRect){