iOS开发block传值基本使用方法
2016-08-05 11:21
316 查看
/**A : .m*/
#import “controllerA.h”
#import "controllerB.h”
@interface controllerA ()
@property (nonatomic,
strong) UITextField *textFieldA;
@property (nonatomic,
strong) UIButton *buttonA;
@implementation controllerA
部分代码…………省略
按钮的跳转事件
- (void)buttonClick:(UIButton *)buttonA{
controllerB *controller =[[controllerB
alloc]init];
controller.returnTextBlock = ^(NSString *showText){
self.textFieldA.text = showText;
};
[self
presentViewController:controller
animated:YES
completion:nil];
}
@end
/**B : .h*/
#import <UIKit/UIKit.h>
typedef void(^ReturnTextBlock)(NSString *showText);
@interface controller :
UIViewController
@property (nonatomic,
copy) ReturnTextBlock returnTextBlock;
@property (nonatomic,
strong) UITextField *textFieldB;
@end
/**B : .m*/
#import “controllerA.h”
#import "controllerB.h”
@interface controllerB ()
@property (nonatomic,
strong) UITextField *textFieldB;
@property (nonatomic,
strong) UIButton *buttonB;
@implementation controllerB
部分代码…………省略
按钮的跳转事件
- (void)buttonClick:(UIButton *)buttonB{
if (self.returnTextBlock) {
self.returnTextBlock(self.textFieldB.text);
}
[self
dismissViewControllerAnimated:YES
completion:nil];
}
@end
#import “controllerA.h”
#import "controllerB.h”
@interface controllerA ()
@property (nonatomic,
strong) UITextField *textFieldA;
@property (nonatomic,
strong) UIButton *buttonA;
@implementation controllerA
部分代码…………省略
按钮的跳转事件
- (void)buttonClick:(UIButton *)buttonA{
controllerB *controller =[[controllerB
alloc]init];
controller.returnTextBlock = ^(NSString *showText){
self.textFieldA.text = showText;
};
[self
presentViewController:controller
animated:YES
completion:nil];
}
@end
/**B : .h*/
#import <UIKit/UIKit.h>
typedef void(^ReturnTextBlock)(NSString *showText);
@interface controller :
UIViewController
@property (nonatomic,
copy) ReturnTextBlock returnTextBlock;
@property (nonatomic,
strong) UITextField *textFieldB;
@end
/**B : .m*/
#import “controllerA.h”
#import "controllerB.h”
@interface controllerB ()
@property (nonatomic,
strong) UITextField *textFieldB;
@property (nonatomic,
strong) UIButton *buttonB;
@implementation controllerB
部分代码…………省略
按钮的跳转事件
- (void)buttonClick:(UIButton *)buttonB{
if (self.returnTextBlock) {
self.returnTextBlock(self.textFieldB.text);
}
[self
dismissViewControllerAnimated:YES
completion:nil];
}
@end
相关文章推荐
- iOS开发中WebView的基本使用方法简介
- iOS开发中对于摄像头的一些基本使用方法分享
- iOS多线程应用开发中使用NSOperation类的基本方法
- iOS开发OC基础:OC集合NSSet、NSMutableSet以及NSCountedSet的基本方法的使用
- iOS开发——网络篇——NSURLSession,下载、上传代理方法,利用NSURLSession断点下载,AFN基本使用,网络检测,NSURLConnection补充
- iOS开发 Block的使用方法和规范,以及可能遇到的问题
- ios开发中使用copy类型的block时,防止循环利用的方法。
- iOS开发之Core Animation基本的使用方法
- iOS开发OC基础:OC字典NSDictionary以及NSMutableDictionary基本方法的使用
- IOS开发基础Object-C( 15)-- block的使用方法
- iOS开发教程之XLForm的基本使用方法
- iOS开发中UITableview控件的基本使用及性能优化方法
- iOS开发中block基本使用
- IOS开发 block(代码块)基本使用
- iOS开发中block的声明、创建、传参的基本使用
- iOS 网络开发NSURLConnection——使用block回调方法发送异步请求
- iOS开发-(^)代码块(block)的使用
- IOS开发之UIView的基本使用
- iOS开发>>>openURL的使用方法