blo

作者: liuguilin | 来源:发表于2017-09-04 19:03 被阅读0次

入门级


此处只简单举例并不深究。对于初学者来说delegate或block都不是一下子能理解的,所以我的建议和体会就是,理不理解咱先不说,我先把这个格式记住,对就是格式,delegate或block都是高度格式化的,用的多了自然而然不理解也就理解了。


B界面

1. 在B中声明一个block

typealias myBlock = (_ str :String)->Void

2.声明一个变量

var textBlock:myBlock?

3. 定义一个方法,方法的参数为和myBlock类型一致的闭包,并赋值给textBlock

func backValue(_ block: @escaping myBlock) {

textBlock = block

}

4. 调用闭包,设置你想传递的参数,调用前先判定一下,是否已实现

if textBlock != nil {

textBlock!(self.textF.text!)

}

A界面

1. 实现闭包,获取到传递的参数

seconedVC.backValue { (text) in

self.label.text = text

}

github下载地址Demo:https://github.com/liuguilin/block

相关文章

  • blo

    入门级 此处只简单举例并不深究。对于初学者来说delegate或block都不是一下子能理解的,所以我的建议和体会...

  • Blo o d

    自从去年十月份体检得知自己的血小板90g/L,医生建议复查,第二个月复查的在92g/L,便一直定期复查,期间医生建...

  • No such thing as —— Writer's Blo

    不要说没有灵感,没有想法,没有idea。 其实心底是在找好的灵感,好的想法,好的idea。 自己给自己设置了太高的...

  • Decentralizing Privacy:Using Blo

    Abstract This paper mainly discuss the application of blo...

  • Cache Lab Implementation and Blo

    Aakash SabharwalJ 部分2013 年 10 月 7 日 欢迎来到指针的世界! 课程时间安排 Cac...

  • 【Elasticsearch】index [index] blo

    ES保存是报标题错误,大致意思是ES只允许读,不允许写。 1、排查问题 ES环境是通过docker部署,先找到es...

  • 004 泪与花

    It is the tears of the earth that keep here smiles in blo...

  • 《飞鸟集》试译(四)

    It is the tears of the earth that keep here smiles in blo...

  • ...then sth will be...

    ...then...will...如果...就会......then sth will be...A is blo...

  • 706 寒冬蓉蓉绿意

    When the majority of the creatures have hibernated or blo...

网友评论

      本文标题: blo

      本文链接:https://www.haomeiwen.com/subject/aufejxtx.html