1:delegate或者block传值

import UIKit
class ViewController: UIViewController,TestDelegatePassValueDelegate { @IBOutlet weak var TFContent: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
} override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} @IBAction func delegateOrBlockBtnClick(sender: AnyObject) {
TFContent.text = ""
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let testVCtl = storyBoard.instantiateViewControllerWithIdentifier("TestDelegateOrBlockViewController") as!TestDelegateOrBlockViewController;
/**设置代理*/
testVCtl.delegate = self
/**block回调传值*/
testVCtl.passValueUseBlock { (valueString) -> Void in self.TFContent!.text = valueString as String }
self.navigationController!.pushViewController(testVCtl, animated: true); }
/**代理函数*/
func passValueUseDelegate(valueString: NSString)
{
self.TFContent!.text = valueString as String
} }
import UIKit
import Foundation
/**定义一个block*/
typealias TestBlockCompleteHandler = (valueString: NSString)->Void
/**声明定义协议*/
protocol TestDelegatePassValueDelegate:NSObjectProtocol
{
func passValueUseDelegate(valueString: NSString) } class TestDelegateOrBlockViewController: UIViewController
{ @IBOutlet weak var TFContent: UITextField!
var delegate:TestDelegatePassValueDelegate? var myBlockHandler:TestBlockCompleteHandler?
override func viewDidLoad() {
super.viewDidLoad() // Do any additional setup after loading the view.
} override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} //MARK: - 用代理来实现传值
@IBAction func delegateBtnClick(sender: AnyObject)
{ TFContent.resignFirstResponder()
if ((delegate != nil) && (delegate?.respondsToSelector("passValueUseDelegate:") != nil))
{
delegate?.passValueUseDelegate(TFContent.text!) }
self.navigationController?.popViewControllerAnimated(true) } //MARK: - 用block来实现传值
@IBAction func blockBtnClick(sender: AnyObject)
{ TFContent.resignFirstResponder()
myBlockHandler?(valueString: self.TFContent.text!)
self.navigationController?.popViewControllerAnimated(true) } func passValueUseBlock(blockHandler: TestBlockCompleteHandler)
{
myBlockHandler = blockHandler }

最新文章

  1. bzoj3732: Network--kruskal最小生成树+LCA
  2. Android--Retrofit+RxJava的简单封装(三)
  3. WCF配置工具及服务调试工具
  4. sqlserver中索引优化
  5. HDU 5706 GirlCat (DFS,暴力)
  6. Mac下kernel_task占用大量CPU怎么办?
  7. c编写程序完成m名旅客和n辆汽车的同步程序代写
  8. linux umount 提示device is busy 的解决
  9. jvm常量池 vsv为什么1000 == 1000返回为False,而100 == 100会返回为True?
  10. poj 1087.A Plug for UNIX (最大流)
  11. nova-network
  12. JDK5什么是新的线程锁技术(两)
  13. spring mvc 注解入门示例
  14. NodeJS 常用模块积累
  15. PHP foreach 循环
  16. windows(xshell)免密码登录
  17. 第一天Python
  18. Dota 2 中安装包的作用
  19. POSTMAN模拟http请求
  20. 关于face alglimnment各种资料,存下来有空慢慢看

热门文章

  1. PAT 1060. Are They Equal
  2. 《hello-world》第八次团队作业:Alpha冲刺-Scrum Meeting 4
  3. Vue项目搭建及原理四
  4. ansible使用jinja2管理配置文件以及jinja2语法简介
  5. [cf 599C] Day at the Beach
  6. poj1330 lca 最近公共祖先问题学习笔记
  7. 装饰器 转载自 http://www.cnblogs.com/huxi/archive/2011/03/01/1967600.html
  8. iOS:改变UITableViewCell的选中背景色
  9. PyQt5学习随笔01--计算一个目录里我们码的代码行数&&PyQt的多线程通信
  10. java电影站点开发经验3