美文网首页
swift 中的block(OC的说话)的使用 实际是“闭包”

swift 中的block(OC的说话)的使用 实际是“闭包”

作者: 林希品 | 来源:发表于2022-11-27 15:56 被阅读0次

1.首先在B中声明一个闭包,然后把闭包声明成属性:

import UIKit
typealias collectionViewblcok = (String) ->()
class CollectionViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {}

2.在B中,选中部分为按钮点击事件:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    clickCollectionView!("点击collectionView")
}

3.在A中,写法为选中部分:

//weak var weakSelf = self
let collectionVC = CollectionViewController()
collectionVC.clickCollectionView = {(param) ->()in

}
self.navigationController?.pushViewController(collectionVC, animated: true)

相关文章

网友评论

      本文标题:swift 中的block(OC的说话)的使用 实际是“闭包”

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