页面传值总结Block
// AppDelegate.m
// 页面传值总结
//
// Created by qianfeng on 15/6/13.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ViewController *ctr = [[ViewController alloc]init];
UINavigationController*nav = [[UINavigationController alloc]initWithRootViewController:ctr];
self.window.rootViewController = nav; return YES;
}
//
// ViewController.m
// 页面传值总结
//
// Created by qianfeng on 15/6/13.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import "ViewController.h"
#import "DetailVIewController.h" @interface ViewController ()
{
UILabel*_label; }
@property(nonatomic,strong)UILabel*label; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; //用于显示第二个界面传过来的数据。
_label = [[UILabel alloc]initWithFrame:CGRectMake(120, 220, 100, 40)];
_label.backgroundColor = [UIColor orangeColor];
[self.view addSubview:_label]; //创建用于跳转到第二个界面的按钮;
UIButton*btn = [self createBtnFrame:CGRectMake(120, 300, 100, 40) title:@"跳转" target:self action:@selector(clickBtn:)];
btn.backgroundColor = [UIColor grayColor];
[self.view addSubview:btn]; } -(void)clickBtn:(id)sender
{
DetailVIewController*ctr = [[DetailVIewController alloc]init];
__weak ViewController*weakself =self;
ctr.clockBlock = ^(NSString*title){
weakself.label.text = title; };
[self.navigationController pushViewController:ctr animated:YES]; } -(UIButton*)createBtnFrame:(CGRect)frame title:(NSString*)title target:(id)target action:(SEL)action
{
UIButton*btn= [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = frame;
[btn setTitle:title forState:UIControlStateNormal];
[btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; return btn; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
//
// DetailVIewController.h
// 页面传值总结
//
// Created by qianfeng on 15/6/13.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import <UIKit/UIKit.h> @interface DetailVIewController : UIViewController //声明block
@property(nonatomic,copy)void(^clockBlock)(NSString*titler); @end //
// DetailVIewController.m
// 页面传值总结
//
// Created by qianfeng on 15/6/13.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import "DetailVIewController.h" @implementation DetailVIewController -(void)viewDidLoad
{
[super viewDidLoad] ;
self.view.backgroundColor = [UIColor whiteColor]; UIButton*bt1 = [self createBtnFrame:CGRectMake(200, 140, 100, 40) title:@"block传值" target:self action:@selector(blockClick:)];
[self.view addSubview:bt1]; }
-(void)blockClick:(UIButton*)sender
{
NSString*title = [sender currentTitle]; if (self.clockBlock) {
self.clockBlock(title);
}
}
-(UIButton*)createBtnFrame:(CGRect)frame title:(NSString*)title target:(id)target action:(SEL)action
{
UIButton*btn= [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = frame;
[btn setTitle:title forState:UIControlStateNormal];
[btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; return btn; } @end
页面传值总结Block的更多相关文章
- block 页面传值小结
我以自己项目中的一个模块为例,首先有两个页面,第一个页面为显示城市页面,第二个页面为选择要使用block传的值(城市名). 第一个页面中的显示控件: //自定义左部定位视图 self.locView ...
- ios常见的页面传值方式
iOS页面间的传值细分有很多种,基本的传值方式有三种:委托Delegate传值.通知NSNotification传值.Block传值,其他在项目中可能会遇到的还有:UserDefault或文件方式传值 ...
- iOS页面传值方式
普遍传值方式如下: 1.委托delegate方式: 2.通知notification方式: 3.block方式: 4.UserDefault或者文件方式: 5.单例模式方式: 6.通过设置属性,实现页 ...
- ASP.NET MVC 5 Web编程5 -- 页面传值的方式
本篇文章将讲述MVC的页面传值方式,具体包括:后端向前端传值(Controller向View传值):前端向后端传值(View向Controller传值):Action与Action之间的传值. 回顾 ...
- WebForm 页面传值
一.使用Querystring Querystring是一种非常简单的传值方式,其缺点就是会把要传送的值显示在浏览器的地址栏中,并且在此方法中不能够传递对象.如果你想传递一个安全性不是那么太重要或者是 ...
- Spring 向页面传值以及接受页面传过来的参数的方式
来源于:http://www.cnblogs.com/liuhongfeng/p/4802013.html 一.从页面接收参数 Spring MVC接收请求提交的参数值的几种方法: 使用HttpSer ...
- ASP.NET页面传值不使用QueryString
ASP.NET页面传值不使用QueryString Asp.net中的页面传值方法: 1 Url传值 特点:主要优点是实现起来非常简单,然而它的缺点是传递的值是会显示在浏览器的地址 ...
- artdialog4.1.7 中父页面给子页面传值
artdialog4.1.7中父页面给子页面传值时看了一些网友的解决方法: 在父页面声明全局变量 var returnValue=“ ”,子页面用art.dialog.opener.returnVal ...
- webform页面传值和删除修改
一.webform跨页面传值1.内置对象地址栏数据拼接 QueryString 优点:简单好用:速度快:不消耗服务器内存. 缺点:只能传字符串:保密性差(调转页面后在地址栏显示):长度有限.响应请求对 ...
随机推荐
- [Node.js] Level 7. Persisting Data
Simple Redis Commands Let's start practicing using the redis key-value store from our node applicati ...
- linux查看CPU性能及工作状态的指令
http://www.aikaiyuan.com/9347.html http://blog.csdn.net/jk110333/article/details/8683478 http://www. ...
- Spark SQL - DataFrame
1 Overview Spark SQL is a Spark module for structured data processing. It provides a programming abs ...
- 谈C#中的Delegate
引言 Delegate是Dotnet1.0的时候已经存在的特性了,但由于在实际工作中一直没有机会使用Delegate这个特性,所以一直没有对它作整理.这两天,我再度翻阅了一些关于Delegate的资料 ...
- SMO优化算法(Sequential minimal optimization)
原文:http://www.cnblogs.com/jerrylead/archive/2011/03/18/1988419.html SMO算法由Microsoft Research的John C. ...
- apache apr介绍
APR(Apache portable Run-time libraries,Apache可移植运行库)的目的如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库.在早 ...
- B - 娜娜梦游仙境系列——跳远女王
B - 娜娜梦游仙境系列——跳远女王 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Other ...
- MD5Encoder加密支持utf-8
import java.security.MessageDigest; public class MD5Encoder { public static String encode(String str ...
- ASP.NET页面与IIS底层交互和工作原理详解(第二回)
引言 在 Part.1 Http请求处理流程 一文中,我们了解了Http请求的处理过程以及其它一些运作原理.我们知道Http管道中有两个可用接口,一个是IHttpHandler,一个是IHttpMod ...
- ilter()和find()的区别
这是jQuery里常用的2个方法.他们2者功能是完全不同的,而初学者往往会被误导. 首先 我们看.find()方法:现在有一个页面,里面HTML代码为;程序代码 <div class=" ...