Swift Delegate使用
来源:互联网 发布:mac npm安装webpack 编辑:程序博客网 时间:2024/06/05 04:34
我们以UItableViewcell里按钮点点击事件作为例子
在cell里声明一个delegate
weak var delegate:MZAccumulateCellDelegate?
需要实现的方法
protocol MZAccumulateCellDelegate:NSObjectProtocol { func buyButtonDidClick(sender:UIButton,model:contentModel) -> Void}
给按钮添加点击事件
buyBtn?.addTarget(self, action: #selector(clickBuyBtn(_:)), for: .touchUpInside)
传递delegate
func clickBuyBtn(_ sender:UIButton) -> Void { delegate?.buyButtonDidClick(sender: sender, model: model) }
在VC里准守代理
MZAccumulateCellDelegate
cell?.delegate = self
实现方法
func buyButtonDidClick(sender: UIButton, model: contentModel) { if !MZOAuthManager.sharedInstance.isAuthorized() { self.gotoLogin() return; } let buyVC = MZBuyGoldViewController.init() buyVC.productId = model.id buyVC.isRegular = true self.navigationController?.pushViewController(buyVC, animated: true) }
0 0
- Swift Delegate使用
- swift delegate
- Swift - Delegate
- swift delegate
- Swift基础之Delegate方法的使用
- Swift中Delegate的正确使用姿势
- Swift - 委托(delegate)的介绍,及使用样例
- Swift-代理-delegate
- swift 中的delegate 写法
- Swift 中的代理 (Delegate)
- delegate 使用
- Swift入门教程18-代理Delegate
- 如何理解swift中的delegate
- 如何理解swift中的delegate
- Swift中Delegate代理声明和实现
- Swift语言精要 - 浅谈代理模式(Delegate)
- Swift UIViewController中的delegate方式传值
- Swift UIViewController中的delegate方式传值
- Linux 下使用脚本进行SSH授权及命令操作
- ios证书 develop distribution ad-hoc 区别
- Linux学习笔记13 grep,egrep,bash变量
- 使用Gson将List转化为JSON并转回List
- JAVA微信开发-新手接入指南
- Swift Delegate使用
- templete模板each循环和if用法
- 欢迎使用CSDN-markdown编辑器
- 基于Django1.8.2文档,编写第一个Django应用(1)
- Android Studio中Git的配置及协同开发
- maven依赖的版本管理
- [UOJ#34]多项式乘法(FFT)
- Android MVP +Retrofit+RxJava
- 在Ubuntu上安装、配置和部署Rocket.Chat