Customised delegate 自定义代理
来源:互联网 发布:nginx 压力测试 编辑:程序博客网 时间:2024/05/16 13:53
The example is for nesting a smallCollectionVIew into a BigCollectionViewCell, whose collection view is constructed in BigCollectionViewController. Going tomanipulate bigCollectionView in one VC through clicking cell of smallCollectionView in another class.
1. Delegate definition
Where: BigCollectionViewCell.swift (which file you want to call a delegate function)
protocol BigCategoryCellDelegate :class {
func didSelectSmallCell (#indexPath:NSIndexPath)
}
2. Create delegate property
Where:BigCollectionViewCell.swift (a property of BigCollectionViewCell class)
weakvar delegate: BigCategoryCellDelegate?
3. Function call
Where:BigCollectionViewCell.swift (collectionView = smallCollectionVIew)
func collectionView(collectionView:UICollectionView, didSelectItemAtIndexPath indexPath:NSIndexPath) {
self.delegate?.didSelectSmallCell(indexPath: indexPath)
}
-----------------------------------------s-e-p-e-r-a-t-o-r----------------------------------------------
4. Inherit the delegate
where: BigCollectionViewController.swift (whose property you want to manipulate)
class BigCollectionViewController: UIViewController, ..., BigCategoryCellDelegate {}
5. Link the delegate
where:BigCollectionViewController.swift (right after the BigCollectionViewCell() is dequeued)
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("bigCollectionViewCell", forIndexPath: indexPath) as? BigCollectionViewCell
cell?.delegate =self
6. Function Definition
where:BigCollectionViewController.swift
func didSelectSmallCell (#indexPath:NSIndexPath){
...
bigCollectionView?.reloadData()
}
- Customised delegate 自定义代理
- 192,自定义代理delegate
- QTableWidget 实现自定义代理(delegate)
- delegate 代理
- IOS学习之——自定义代理 delegate
- IOS学习之——自定义代理delegate
- Customised collectionView
- C#中的代理(Delegate)
- 代理(delegate)问题
- delegate,C#,代理
- C#中的代理(Delegate)
- C#中的代理(Delegate)
- C#中的代理(Delegate)
- C#中的代理(Delegate)
- C#中的代理(Delegate)
- Delegate代理实现
- Swift-代理-delegate
- Delegate 代理步骤
- template模板
- 在android apk中使用internal包
- DBUtils的使用
- androidUI虚线解决方案
- android命令行网络时间同步
- Customised delegate 自定义代理
- IOS中计时器NSTimer的使用
- 如何进行不同容量硬盘对拷
- hadoop2.7完全分布式安装
- 对于前段传的参数的拼装
- 让程序员跳槽的非钱原因
- 用发消息方式实现加法运算
- 黑马day04 表单请求参数&中文乱码分析
- 关注技术-互联网人物