页面传值总结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 优点:简单好用:速度快:不消耗服务器内存. 缺点:只能传字符串:保密性差(调转页面后在地址栏显示):长度有限.响应请求对 ...
随机推荐
- [Angular 2 Router] Configure Your First Angular 2 Route
Using the Angular 2 router requires defining routes, passing them in to the RouterModule.forRoot and ...
- 淘宝 印风 UDF
http://blog.csdn.net/zhaiwx1987/article/details/6902623
- QQ上传大文件为什么这么快
今天和同事在群里讨论“QQ上传大文件/QQ群发送大文件时,可以在极短的时间内完成”是如何做到的. 有时候我们通过QQ上传一个几百M的文件,竟然只用了几秒钟,从带宽上限制可以得出,实际上传文件是不可能的 ...
- apache apr介绍
APR(Apache portable Run-time libraries,Apache可移植运行库)的目的如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库.在早 ...
- HTML5图片拖拽预览原理及实现
一.前言 这两天恰好有一位同事问我怎样做一个图片预览功能.作为现代人的我们首先想到的当然是HTML5啦,其实HTML5做图片预览已经是一个老生常谈的问题了.我在这里就简单说说其中相关的一些东西,当然会 ...
- BootStrap2学习日记23---图片轮播
<div id="carousel1" class="carousel slide"> <div class="carousel-i ...
- oracle数据库常用SQL语句
1)删除表的一列 ALTER TABLE 表名 DROP COLUMN 列名; 2)增加表的一列 且默认值为0 alter table 表名 add 字段名 类型 default '0'; 3)修改表 ...
- Android 高级UI设计笔记18:实现圆角图片
1. 下面我们经常在APP中看到的圆角图片,如下: 再比如:微信聊天会话列表的头像是圆角的. 2. 下面分析一个Github的经典: (1)Github库地址: https://github.com/ ...
- 干货:VLDB论文摘要-阿里技术突破性创新
阿里技术突破性创新 世界顶级大规模数据处理分析管理会议VLDB(VERY LARGE DATA BASE)于9月1日至5日在杭州举办,该会议也是也是大数据云计算领域的盛会,阿里巴巴两个团队在这个会议上 ...
- 【开源项目7】Android视图注入库:butterknife
介绍 ButterKnife通过@InjectView和视图的ID注解的变量去找到并自动转换为你布局上相应的布局视图. class ExampleActivity extends Activity { ...