2、从前一个界面到后一个界面
注意:解题思路
 葵花宝典:属性传值
 第一步:在下一个界面视图控制器的.h文件中定义一个属性
 第二步:在push之前将数据存储到属性中
 第三步:取出属性中的值让控件显示
 从后一个界面往前一个界面传值
 辟邪剑谱:代理传值
代理传值示意图:





注意:从后一个页面往前不相邻的一个界面传值用单例
——————————————————————————————
AppDelegate.m
 //创建根视图控制器firstVC

FirstViewController
*firstVC =
[[FirstViewController
alloc]init];

//创建导航控制器

UINavigationController
*navigationController
= [[UINavigationController
alloc]initWithRootViewController:firstVC];

self.window.rootViewController
=
navigationController;

   
[firstVC release];

   
[navigationController release];
———————————————————————————————
FirstViewController.m
#warning 代理传值第四步
代理对象所在的类遵循协议
@interface
FirstViewController
()<</span>SecondViewControllerDelegate>

@end
@implementation
FirstViewController
-
(void)passValue:(NSString
*)string{

#warning
代理传值第五步  实现协议中的方法
   
((UILabel
*)[self.view
viewWithTag:202]).text
=
string;
}
-
(void)viewWillDisappear:(BOOL)animated{

((UILabel
*)[self.view
viewWithTag:202]).text
=
[SingleLeton__
shareSingleLeton].string;

}

- (void)viewDidLoad
{

   
[super
viewDidLoad];
   
self.view.backgroundColor
=
[UIColor
cyanColor];
   
//建立一个label

UILabel
*label =
[[UILabel
alloc]initWithFrame:CGRectMake(30,
84,
260,
40)];

label.tag
=
202;

label.backgroundColor
=
[UIColor
whiteColor];

label.text
=
@"你爱她吗?";

   
label.textColor
=
[UIColor
redColor];
   
#warning 单例传值第五步  
取出单例中属性中存储的数据,赋值给空间
   
label.text
=
[SingleLeton__
shareSingleLeton].string;
   
[self.view
addSubview:label];
   
[label release];
   
//建立一个textField

UITextField
*field =
[[UITextField
alloc]initWithFrame:CGRectMake(30,
164,
260,
40)];

//第三步加tag值

field.tag
=
200;

field.borderStyle
=
UITextBorderStyleRoundedRect;

field.placeholder
=
@"请输入内容";

field.textColor
=
[UIColor
redColor];

[self.view
addSubview:field];

   
[field release];

   //建立一个button
   
UIButton
*button =
[UIButton
buttonWithType:UIButtonTypeCustom];

button.frame
=
CGRectMake(30,
244,
260,
40);

[button setTitle:@"进入下一页"
forState:UIControlStateNormal];

button.tintColor
=
[UIColor
redColor];

button.backgroundColor
=
[UIColor
grayColor];

[button addTarget:self
action:@selector(handlePassValue
: ) forControlEvents:(UIControlEventTouchUpInside)];

[self.view
addSubview:button];

[self
configureCommonProerty];

self.navigationController.navigationBar.tintColor
=
[UIColor
redColor];

}
#pragma mark
公共方法
-
(void)configureCommonProerty{

//设置导航条背景图片

[self.navigationController.navigationBar
setBackgroundImage:[UIImage
imageNamed:@"1"]
forBarMetrics:UIBarMetricsDefault];

}



- (void)handlePassValue
: (UIButton
*)passValue{

//此时创建的是下一个界面对象

SecondViewController
*second =
[[SecondViewController
alloc]init];

#warning 代理传值第三步
为后一个界面指定代理对象,只能是前一个页面试图控制器对象

   
second.delegate
=
self;
#warning 属性传值第二步
push之前传入数据
   
second.testString 
= ((UITextField
*)[self.view
viewWithTag:200]).text;

   
[self.navigationController
pushViewController:second
animated:YES];

[second release];

}

- (void)customNavigationItemAppearance{

//配置导航条显示的标题

self.navigationItem.title
=
@"第一页";

}
代理传值效果:





——————————————————————————
SecondViewController.h

#warning 代理传值第一步
定义协议
@protocol
SecondViewControllerDelegate
<</span>NSObject>

- (void)passValue
: (NSString
*)string;
@end

@interface
SecondViewController
: UIViewController

#warning
属性传值第一步 
定义属性且属性的类型要和要传入的数据类型要保持一致

@property(nonatomic,copy)NSString
*testString;
#warning 代理传值第二步
定义代理属性
@property(nonatomic,assign)id<</span>SecondViewControllerDelegate>delegate;
@end
属性传值效果:



———————————————————————————
SecondViewController.m
//建立一个label

UILabel
*label =
[[UILabel
alloc]initWithFrame:CGRectMake(30,
84,
260,
40)];

label.backgroundColor
=
[UIColor
whiteColor];

label.text
=
@"给我下一页的内容";

#warning 属性传值的第三步 
取出数据让控件显示
   
label.text
=
self.testString;

label.textColor
=
[UIColor
redColor];

[self.view
addSubview:label];

[label release];

//建立一个textField

UITextField
*field =
[[UITextField
alloc]initWithFrame:CGRectMake(30,
164,
260,
40)];

field.tag
=
203;

field.borderStyle
=
UITextBorderStyleRoundedRect;

field.placeholder
=
@"请输入第二页的内容";

field.textColor
=
[UIColor
redColor];

[self.view
addSubview:field];

[field release];

//建立一个button

UIButton
*button =
[UIButton
buttonWithType:UIButtonTypeCustom];

button.frame
=
CGRectMake(30,
244,
260,
40);

[button setTitle:@"进入下一页"
forState:UIControlStateNormal];

button.tintColor
=
[UIColor
redColor];

button.backgroundColor
=
[UIColor
grayColor];

[button addTarget:self
action:@selector(handlePassValue
:) forControlEvents:(UIControlEventTouchUpInside)];

[self.view
addSubview:button];

//建立一个button

UIButton
*button1 =
[UIButton
buttonWithType:UIButtonTypeCustom];

button1.frame
=
CGRectMake(30,
324,
260,
40);

[button1 setTitle:@"返回上一页"
forState:UIControlStateNormal];

button1.tintColor
=
[UIColor
redColor];

button1.backgroundColor
=
[UIColor
grayColor];

[button1 addTarget:self
action:@selector(handlePass
:) forControlEvents:(UIControlEventTouchUpInside)];

[self.view
addSubview:button1];

self.navigationItem.title
=
@"第二页";

}



- (void)handlePassValue
: (UIButton
*)passValue{

ThirdViewController
*third =
[[ThirdViewController
alloc]init];

//传值第三不创建时赋值

   
third.textString
=
((UITextField
*)[self.view
viewWithTag:203]).text;
   
[self.navigationController
pushViewController:third
animated:YES];

[third release];

}
-
(void)handlePass
: (UIButton
*)pass{  
#warning 代理传值第六步
让代理执行协议中的方法
   
NSString
*string =
((UITextField
*)[self.view
viewWithTag:
203]).text;
   
if
([self.delegate
respondsToSelector:@selector(passValue:)])
{
       
[self.delegate
passValue:string];

}
   
[self.navigationController
popViewControllerAnimated:YES];

}
——————————————————————————
ThirdViewController.h
@property(nonatomic,copy)NSString
*textString;
ThirdViewController.m
self.view.backgroundColor
=
[UIColor
greenColor];

//建立一个label

UILabel
*label =
[[UILabel
alloc]initWithFrame:CGRectMake(30,
84,
260,
40)];

label.backgroundColor
=
[UIColor
grayColor];

label.text
=
@"给我第一个页面的内容";

label.text
=
self.textString;

[self.view
addSubview:label];

[label release];

//建立一个textField

UITextField
*field =
[[UITextField
alloc]initWithFrame:CGRectMake(30,
164,
260,
40)];

field.borderStyle
=
UITextBorderStyleRoundedRect;

field.textColor
=
[UIColor
redColor];

field.placeholder
=
@"啦啦啦";

field.tag
=
204;

[self.view
addSubview:field];

[field release];

//建立一个button

UIButton
*button =
[UIButton
buttonWithType:UIButtonTypeCustom];

button.frame
=
CGRectMake(30,
244,
260,
40);

[button setTitle:@"返回"
forState:UIControlStateNormal];

button.tintColor
=
[UIColor
redColor];

button.backgroundColor
=
[UIColor
grayColor];

[button addTarget:self
action:@selector(handlePassValue
:) forControlEvents:(UIControlEventTouchUpInside)];

[self.view
addSubview:button];

self.navigationItem.title
=
@"第三页";

}

- (void)handlePassValue
: (UIButton
*)passValue{

#warning 单例传值第四步 
给单例对象的属性赋值
[SingleLeton__
shareSingleLeton].string 
=  ((UITextField
*)[self.view
viewWithTag:204]).text;

[self.navigationController
popToRootViewControllerAnimated:YES];

}
————————————————————————————
SingleLeton单例.h
#warning 单例传值第一步
,定义单例类,继承自NSObject

#import

@interface
SingleLeton__
: NSObject

#warning 单例传值第二步
定义单例类的创建的方法
//share stand
main   创建单例对象方法常用的开头

+ (SingleLeton__
*)shareSingleLeton;
#warning
单例传值第三步 
定义属性,存储传输的数据,属性的类型要和传输数据的类型保持一致
@property(nonatomic,copy)NSString
*string;
@end
单例传值效果:



————————————————————————————
SingleLeton单例.m
//定义一个有static
修饰的SingleLeton对象
//static
修饰的变量的生命周期和应用程序的生命周期一样长,只有程序退出后台的时候才被销毁
static
SingleLeton__
*single
= nil;

+ (SingleLeton__
*)shareSingleLeton{

//single等于nil还没被初始化,所以在if语句对其初始化

//实时同步单例对象的创建,保护其在多线程下的安全

@synchronized(self){

if
(single
==
nil)
{

       
single
=
[[SingleLeton__
alloc]init];

}

}

   
return
single;

}

- (void)dealloc{

self.string
=
nil;

[super
dealloc];

}
================================================
导航控制器——UI-第八天(上):http://blog.sina.com.cn/s/blog_814ecfa90102vvzu.html

欢迎学习本文,未经博主许可禁止转载!

UIPassValue页面传值&nbsp;UI_08(下)的更多相关文章

  1. ASP.NET MVC 5 Web编程5 -- 页面传值的方式

    本篇文章将讲述MVC的页面传值方式,具体包括:后端向前端传值(Controller向View传值):前端向后端传值(View向Controller传值):Action与Action之间的传值. 回顾 ...

  2. WebForm 页面传值

    一.使用Querystring Querystring是一种非常简单的传值方式,其缺点就是会把要传送的值显示在浏览器的地址栏中,并且在此方法中不能够传递对象.如果你想传递一个安全性不是那么太重要或者是 ...

  3. net面试 ASP.NET页面传值的各种方法和分析 (copy)

    Web页面是无状态的, 服务器对每一次请求都认为来自不同用户,因此,变量的状态在连续对同一页面的多次请求之间或在页面跳转时不会被保留.在用ASP.NET 设计开发一个Web系统时, 遇到一个重要的问题 ...

  4. Spring 向页面传值以及接受页面传过来的参数的方式

    来源于:http://www.cnblogs.com/liuhongfeng/p/4802013.html 一.从页面接收参数 Spring MVC接收请求提交的参数值的几种方法: 使用HttpSer ...

  5. ASP.NET页面传值不使用QueryString

    ASP.NET页面传值不使用QueryString   Asp.net中的页面传值方法: 1         Url传值 特点:主要优点是实现起来非常简单,然而它的缺点是传递的值是会显示在浏览器的地址 ...

  6. artdialog4.1.7 中父页面给子页面传值

    artdialog4.1.7中父页面给子页面传值时看了一些网友的解决方法: 在父页面声明全局变量 var returnValue=“ ”,子页面用art.dialog.opener.returnVal ...

  7. webform页面传值和删除修改

    一.webform跨页面传值1.内置对象地址栏数据拼接 QueryString 优点:简单好用:速度快:不消耗服务器内存. 缺点:只能传字符串:保密性差(调转页面后在地址栏显示):长度有限.响应请求对 ...

  8. c#ASP.NET中页面传值共有这么几种方式

    一.目前在ASP.NET中页面传值共有这么几种方式: 1.Response.Redirect("http://www.hao123.com",false); 目标页面和原页面可以在 ...

  9. webform 页面传值的方法总结

    ASP.NET页面之间传递值的几种方式   页面传值是学习asp.net初期都会面临的一个问题,总的来说有页面传值.存储对象传值.ajax.类.model.表单等.但是一般来说,常用的较简单有Quer ...

随机推荐

  1. samba服务器配置过程

    SAMBA服务器配置 yum install samba samba-client samba-swat 改变文件权限及用户 vi /etc/samba/smb.conf d+G全删注释 复制下面代码 ...

  2. 通过ajax和spring 后台传输json数据

    在通过ajax从页面向后台传数据的时候,总是返回415(Unsupported media type)错误,后台无法获取数据.如下图所示: 在尝试解决这个问题的时候,我们首先要理解一下概念: @req ...

  3. Radio Station

    B. Radio Station time limit per test:  2 seconds memory limit per test:  256 megabytes input: standa ...

  4. windows系统和centos双系统安装引导项修改

    在CentOS下修改Linux引导文件:     (1)找到win10的引导 1.首先我们点击第一个系统进入centos           2.运行终端,敲入命令su,为了获取管理员权限,然后终端提 ...

  5. JAVAEE——BOS物流项目11:在realm中授权、shiro的方法注解权限控制、shiro的标签权限控制、总结shiro的权限控制方式、权限管理

    1 学习计划 1.在realm中进行授权 2.使用shiro的方法注解方式权限控制 n 在spring文件中配置开启shiro注解支持 n 在Action方法上使用注解 3.★使用shiro的标签进行 ...

  6. python转lua最容易掉进去的坑--作用域

    你以为会依次打印2,4,8吗? 错. 2,2,2 value = 1 for i=1,3 do local value = value*2 print(value) end 你以为打印1吗?,错,输出 ...

  7. Hibernate与JPA的区别是什么

    翻译来源:https://www.quora.com/What-is-the-difference-between-Hibernate-and-JPA 本文作者:苏生米沿 本文地址:http://bl ...

  8. Android的Spinner控件用法解析

    微调框 微调框提供一种方法,让用户可以从值集中快速选择一个值.默认状态下,微调框显示其当前所选的值. 触摸微调框可显示下拉菜单,其中列有所有其他可用值,用户可从中选择一个新值. 您可以使用 Spinn ...

  9. 如果用一个循环数组q[0..m-1]表示队列时,该队列只有一个队列头指针front,不设队列尾指针rear,求这个队列中从队列投到队列尾的元素个数(包含队列头、队列尾)。

    #include <iostream> using namespace std; //循环队列(少用一个空间)长度 #define M (8+1) typedef struct node ...

  10. Apache commons email 使用过程中遇到的问题

    apache-commons-email是对mail的一个封装,所以使用起来确实是很方便.特别的,官网上的tutorial也是极其的简单.但是我也仍然是遇到了没有解决的问题. jar包的添加 mail ...