//  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的更多相关文章

  1. block 页面传值小结

    我以自己项目中的一个模块为例,首先有两个页面,第一个页面为显示城市页面,第二个页面为选择要使用block传的值(城市名). 第一个页面中的显示控件: //自定义左部定位视图 self.locView ...

  2. ios常见的页面传值方式

    iOS页面间的传值细分有很多种,基本的传值方式有三种:委托Delegate传值.通知NSNotification传值.Block传值,其他在项目中可能会遇到的还有:UserDefault或文件方式传值 ...

  3. iOS页面传值方式

    普遍传值方式如下: 1.委托delegate方式: 2.通知notification方式: 3.block方式: 4.UserDefault或者文件方式: 5.单例模式方式: 6.通过设置属性,实现页 ...

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

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

  5. WebForm 页面传值

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

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

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

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

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

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

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

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

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

随机推荐

  1. 【C语言】模拟实现库函数strcat函数

    //模拟实现库函数strcat函数 #include <stdio.h> #include <string.h> #include <assert.h> char ...

  2. android复制数据库到SD卡(网上搜集,未经验证)

    android中使用sqlite.复制assets下的数据库到SD卡.支持大于1M的文件 如果使用SD卡,需要在AndroidManifest.xml中设置权限 <uses-permission ...

  3. Autolayout环境设置任意个数相等间距排列的按钮的方法

    摘要: 在storyboard中,想要用autolayout设置多个按钮按照相同的间距排列,并且自动根据屏幕宽度调整间距大小,就我了解的来说,没有直接的设置方法.我用storyboard+代码的方法实 ...

  4. Android 动画机制与使用技巧

    动画效果一直是人机交互中非常重要的部分,与死板.突兀的显示效果不同,动画效果的加入,让交互变得更加友好,特别是在提示.引导类的场景中,合理地使用动画能让用户获得更加愉悦的使用体验 一.Android ...

  5. purge

    RR级别 mysql V5.6 debug ; 测试1 会话1: mysql)); Query OK, rows affected (0.04 sec) mysql,"a"); Q ...

  6. ci框架学习中注意的事项

    视图: 加载视图:$this->load->view('name'); 一次可以加载多个视图,如: public function index() { $data['page_title' ...

  7. 分享10款常用的jQuery焦点图插件

    爱编程一直在收集整理编程相关的知识和解决方案,今天小编为大家带来10款非常常用的jquery焦点图插件. 1.jQuery可自动播放动画的焦点图插件 之前我们已经分享过很多非常实用的jQuery焦点图 ...

  8. WWH学习模式

    WWH是"What+Why+How"的简称,是对学习方法最完美的概括."如果不按照WWH这种模式来教学,90%的结果是老师没教好,学生学不好." 1.What( ...

  9. A+B Coming

    Problem Description Many classmates said to me that A+B is must needs.If you can’t AC this problem, ...

  10. 使用PIL处理image

    获得一个Image实例 import Image im = Image.open('1.jpg') #返回一个Image对象,open只对图片的头做处理,所以open操作是非常快的 resize,裁剪 ...